[Feature]Upload Modem source code

Change-Id: Id4294f30faced84d3e6fd6d5e61e1111bf287a37
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/README.txt b/mcu/tools/NVRAMStatistic/autogen_v2/README.txt
new file mode 100644
index 0000000..4b6a92c
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/README.txt
@@ -0,0 +1 @@
+Scripts for nvram auto gen refactory
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/__init__.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/__init__.py
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/main.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/main.py
new file mode 100644
index 0000000..0a8c150
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/main.py
@@ -0,0 +1,161 @@
+import operator
+import sys
+import os
+import platform
+
+from .src.initconfig import logical_data_item_table
+from .src.initconfig import const_value
+from .src.initconfig import global_value
+from .src.initconfig import LtableEntry
+from .src.initconfig import printf
+from .src import tableconstructor
+from .src import sys_cache_generator
+from .src import gen_cache_info
+from .src import gen_cat_file
+from .src import gen_lid_information
+from .src import gen_statistic
+from .src import mcf_ota_helper
+from .src import custpackhelper
+from .src import secupackhelper
+from .src import buildtimecheck
+from .src import tableconstructor_win
+
+from .src import gen_assign_entry
+
+
+def main(path):
+    """
+     args:
+        path: gen file output path, path + "nvram_auto_gen" + filename
+    """
+    # set path    
+    global_value.logging_path = path
+    global_value.path = path
+    global_value.autogen_path = os.path.join(global_value.path, "nvram_auto_gen")
+    global_value.log_path = os.path.join(global_value.path, "bin", "log")
+    
+    # check path exist
+    if not os.access(global_value.autogen_path, os.F_OK):
+        printf("error: folder no exist: %s" % global_value.autogen_path)
+        sys.exit(2)
+    if not os.access(global_value.log_path, os.F_OK):
+        printf("error: folder no exist: %s" % global_value.log_path)
+        sys.exit(2)
+	
+	global_value.logger_config()
+    global_value.logger.info("========main========")
+    # set platform
+    global_value.platform = platform.system()
+    if global_value.platform != "Windows" and global_value.platform != "Linux":
+        printf("platform error: platform is not windows or linux!")
+        printf("platform.system() = %s" % platform.system())
+        global_value.logger.error("platform error: platform is not windows or linux!")
+        global_value.logger.error("platform.system() = %s", platform.system())
+        sys.exit(1)
+    
+    global_value.logger.info("path = %s, logging_path = %s, platform = %s", global_value.path, global_value.logging_path
+                             , global_value.platform)
+    
+    global_value.pars_macro_info()
+    
+    if global_value.platform == "Windows":  # windows
+        tableconstructor_win.parse_segment_info_win()
+    elif global_value.platform == "Linux":  # linux  
+        tableconstructor.pars_segment_info()
+    else:
+        pass
+    
+    tableconstructor.parse_lid_table()
+    tableconstructor.parse_lid_item_data()
+    tableconstructor.statistic_lid_item_data()
+
+    # tmp write ltable for NVDB test
+    # tableconstructor.write_logical_table()
+    
+    # sort ,key is lid
+    sort_key = operator.attrgetter('lid')
+    logical_data_item_table.sort(key=sort_key)
+    
+    # # assign entry
+    global_value.logger.info("====================")
+    global_value.logger.info("nvram_gen_assign_entry")
+    gen_assign_entry.nvram_gen_assign_entry()
+    
+    # gen nvram_cache_info.c and nvram_cache_info.h
+    global_value.logger.info("====================")
+    global_value.logger.info("nvram_gen_cache_info")
+    gen_cache_info.nvram_gen_cache_info()
+    
+    # gen custom_nvram_lid_cat.xml
+    global_value.logger.info("====================")
+    global_value.logger.info("nvram_gen_cat_xml")
+    gen_cat_file.nvram_gen_cat_xml()
+    
+    # gen ~nvram_lid_information.log and ~nvram_lid_size.log
+    global_value.logger.info("====================")
+    global_value.logger.info("nvram_gen_info_size_log")
+    gen_lid_information.nvram_gen_info_size_log()
+    
+    # gen nvram_lid_statistics_bak.h
+    global_value.logger.info("====================")
+    global_value.logger.info("nvram_gen_statistic")
+    gen_statistic.nvram_gen_statistic()
+    
+    # gen custom_nvram_restore.c and nvram_restore_dom_new.h
+    global_value.logger.info("====================")
+    global_value.logger.info("nvram_gen_restore_function")
+    sys_cache_generator.nvram_gen_restore_function()    # win || linux
+    
+    # gen nvram_custpack_table.c and nvram_custpack_table_lid.c
+    if (global_value.macro & const_value.__MMI_FMI__) and (not global_value.macro & const_value.__L1_STANDALONE__):
+        global_value.logger.info("====================")
+        global_value.logger.info("nvram_gen_custpack_table")
+        custpackhelper.nvram_gen_custpack_table()
+    
+    # gen custom_nvram_secro.c and custom_nvram_secro_tbl.c
+    if True:  # global_value.macro & const_value.__VENDOR_RELEASE__:
+        global_value.logger.info("====================")
+        global_value.logger.info("nvram_gen_secro")
+        secupackhelper.nvram_gen_secro()    # win || linux
+    
+    # gen nvram_ltable_List.h
+    global_value.logger.info("====================")
+    global_value.logger.info("nvram_gen_ltable_list")
+    mcf_ota_helper.nvram_gen_ltable_list()
+    
+    # gen nvram_lid_list_for_mcf.h
+    global_value.logger.info("====================")
+    global_value.logger.info("nvram_gen_mcf_ota_lid_list")
+    mcf_ota_helper.nvram_gen_mcf_ota_lid_list()
+    
+    global_value.logger.info("====================")
+    global_value.logger.info("build time check: begin")
+    # build time check:lid enum overlapping
+    global_value.logger.info("build time check: lid enum overlapping")
+    buildtimecheck.check_lid_enum_overlapping()
+    buildtimecheck.check_lid_fileprefix_overlapping()
+    # build time check:write protect attr white list
+    global_value.logger.info("build time check: write protect attr white list ")
+    buildtimecheck.check_write_protect()
+    # build time check:cate attr confilicts
+    global_value.logger.info("build time check: cate attr confilicts")
+    buildtimecheck.nvram_gen_check_cate_attr_conflicts()
+    # build time check:hash key check
+    if (global_value.macro & const_value.__NVRAM_LID_HASH_CHECK__) and (global_value.macro & const_value.__MTK_INTERNAL__):
+        global_value.logger.info("build time check: hash key check")
+        buildtimecheck.check_lid_hash_key()
+    # build time check:special lid parameter
+    global_value.logger.info("build time check: special lid parameter")
+    buildtimecheck.check_special_lid_parameter()
+    global_value.logger.info("build time check: end")
+    
+    # gen custom_nvram_database.h
+    global_value.logger.info("build time check: gen custom_nvram_database")
+    tmp_path = os.path.join(path, "nvram_auto_gen", "custom_nvram_database.h")
+    print("custom_nvram database path: {}".format(tmp_path) )
+    f = open(tmp_path, "w")
+    f.close()
+    global_value.logger.info("build time check: end")
+
+if __name__ == '__main__':
+    main()
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/__init__.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/__init__.py
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/buildtimecheck.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/buildtimecheck.py
new file mode 100644
index 0000000..689ee42
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/buildtimecheck.py
@@ -0,0 +1,175 @@
+import hashlib
+import sys
+
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import global_value
+
+nvram_white_list_for_multiple_attr = ("NVRAM_EF_SYS_LID", "NVRAM_EF_IMEI_IMEISV_LID", "NVRAM_EF_NVRAM_LOCK_LID")
+con_type_enum = {
+    "attr_attr": 0,
+    "cate_attr": 1,
+    "cate_cate": 2
+
+}
+nvram_cate_attr_conflict_table = [
+    # attribute conflicts
+    [con_type_enum["attr_attr"], const_value.NVRAM_ATTR_MULTIPLE, const_value.NVRAM_ATTR_PACKAGE],
+    [con_type_enum["attr_attr"], const_value.NVRAM_ATTR_OTA_RESET, const_value.NVRAM_ATTR_RESERVE_BACKWARD],
+    [con_type_enum["attr_attr"], const_value.NVRAM_ATTR_RAW_DATA, (const_value.NVRAM_ATTR_PACKAGE | const_value.NVRAM_ATTR_MULTIPLE | const_value.NVRAM_ATTR_RING)],
+    [con_type_enum["attr_attr"], const_value.NVRAM_ATTR_RAW_DATA, (const_value.NVRAM_ATTR_WRITEPROTECT | const_value.NVRAM_ATTR_CONFIDENTIAL | const_value.NVRAM_ATTR_MSP)],
+
+    # category conflicts
+    [con_type_enum["cate_cate"], const_value.NVRAM_CATEGORY_FUNC_DEFAULT, (const_value.NVRAM_CATEGORY_CUSTPACK | const_value.NVRAM_CATEGORY_SECUPACK)],
+    [con_type_enum["cate_cate"], const_value.NVRAM_CATEGORY_CALIBRAT, ~(const_value.NVRAM_CATEGORY_FUNC_DEFAULT | const_value.NVRAM_CATEGORY_CUSTPACK | const_value.NVRAM_CATEGORY_SECUPACK)],
+    [con_type_enum["cate_cate"], const_value.NVRAM_CATEGORY_IMPORTANT, (const_value.NVRAM_CATEGORY_IMPORTANT_L1 | const_value.NVRAM_CATEGORY_IMPORTANT_L4 | const_value.NVRAM_CATEGORY_INTERNAL | const_value.NVRAM_CATEGORY_OTP)],
+    [con_type_enum["cate_cate"], const_value.NVRAM_CATEGORY_IMPORTANT_L4, (const_value.NVRAM_CATEGORY_IMPORTANT_L1 | const_value.NVRAM_CATEGORY_INTERNAL | const_value.NVRAM_CATEGORY_OTP)],
+    [con_type_enum["cate_cate"], const_value.NVRAM_CATEGORY_IMPORTANT_L1, (const_value.NVRAM_CATEGORY_INTERNAL | const_value.NVRAM_CATEGORY_OTP)],
+    [con_type_enum["cate_cate"], const_value.NVRAM_CATEGORY_INTERNAL, (const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE | const_value.NVRAM_CATEGORY_OTP)],
+    [con_type_enum["cate_cate"], const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE, (const_value.NVRAM_CATEGORY_CUSTPACK | const_value.NVRAM_CATEGORY_SECUPACK | const_value.NVRAM_CATEGORY_OTP)],
+    [con_type_enum["cate_cate"], const_value.NVRAM_CATEGORY_CUSTPACK, (const_value.NVRAM_CATEGORY_SECUPACK | const_value.NVRAM_CATEGORY_OTP)],
+    [con_type_enum["cate_cate"], const_value.NVRAM_CATEGORY_SECUPACK, const_value.NVRAM_CATEGORY_OTP],
+
+    # attribute & category conflicts
+    [con_type_enum["cate_attr"], const_value.NVRAM_CATEGORY_CALIBRAT, (const_value.NVRAM_ATTR_MULTIPLE | const_value.NVRAM_ATTR_MSP | const_value.NVRAM_ATTR_RING)],
+    [con_type_enum["cate_attr"], const_value.NVRAM_CATEGORY_CALIBRAT, (const_value.NVRAM_ATTR_OTA_RESET | const_value.NVRAM_ATTR_RESERVE_BACKWARD)],
+    [con_type_enum["cate_attr"], const_value.NVRAM_CATEGORY_INTERNAL, const_value.NVRAM_ATTR_PACKAGE],
+    [con_type_enum["cate_attr"], const_value.NVRAM_CATEGORY_SECUPACK, (const_value.NVRAM_ATTR_PACKAGE | const_value.NVRAM_ATTR_RAW_DATA)],
+    [con_type_enum["cate_attr"], const_value.NVRAM_CATEGORY_CUSTPACK, const_value.NVRAM_ATTR_RAW_DATA],
+    [con_type_enum["cate_attr"], const_value.NVRAM_CATEGORY_FUNC_DEFAULT, const_value.NVRAM_ATTR_RAW_DATA],
+    [con_type_enum["cate_attr"], const_value.NVRAM_CATEGORY_OTP, const_value.NVRAM_ATTR_AVERAGE | const_value.NVRAM_ATTR_GEN_DEFAULT | const_value.NVRAM_ATTR_RESERVE_BACKWARD | const_value.NVRAM_ATTR_RAW_DATA]
+
+]
+
+
+def check_lid_fileprefix_overlapping():
+    check_result = True
+    for i in range(len(logical_data_item_table)):
+        ldi1 = logical_data_item_table[i]
+        for j in range(i + 1, len(logical_data_item_table)):
+            ldi2 = logical_data_item_table[j]
+            if ldi1.FilePrefix == ldi2.FilePrefix:
+                check_result = False
+                global_value.logger.error(
+                    "duplicated fileprefix and fileverno %s %s of %s and %s\n",
+                    ldi1.FilePrefix, ldi1.FileVerno, ldi1.str_LID, ldi2.str_LID)
+    if not check_result:
+        sys.exit("duplicated fileprefix and fileverno!")
+    
+
+def check_lid_enum_overlapping():
+    check_result = True
+    if len(logical_data_item_table) < 2:
+        global_value.logger.error("Invalid total_lid during CheckLidOverlapping()")
+        sys.exit("Invalid total_lid during CheckLidOverlapping()")
+    for i in range(len(logical_data_item_table)):
+        for j in range(i + 1, len(logical_data_item_table)):
+            if logical_data_item_table[i].lid == logical_data_item_table[j].lid:
+                check_result = False
+                global_value.logger.error(
+                    "%d:%s and %d:%s have same enum value, please check if LID duplicated def or enum"
+                    " value overlapped", i, logical_data_item_table[i].lid, j, logical_data_item_table[j].lid)
+    if not check_result:
+        global_value.logger.error("Please contact NVRAM owner if your NVRAM sub-group size should be enlarged")
+        sys.exit("Please contact NVRAM owner if your NVRAM sub-group size should be enlarged")
+
+
+def check_write_protect():
+    check_result = True
+    for ldi in logical_data_item_table:
+        if ldi.lid == 0 or ldi.size == 0 or ldi.total_records == 0:
+            continue
+        if not ldi.attr & const_value.NVRAM_ATTR_WRITEPROTECT:
+            continue
+        in_list = False
+        for str in nvram_white_list_for_multiple_attr:
+            if ldi.str_LID == str:
+                in_list = True
+                break
+        if not in_list:
+            check_result = False
+            global_value.logger.error("LID %s have WRITE_PROTECT attribute but not in white list!!", ldi.str_LID)
+    if not check_result:
+        global_value.logger.error("Please contact NVRAM owner if your really need this attribute for the LID(s)")
+        sys.exit("Please contact NVRAM owner if your really need this attribute for the LID(s)")
+
+
+def check_special_lid_parameter():
+    check_result = True
+    for ldi in logical_data_item_table:
+        if ldi.attr & const_value.NVRAM_ATTR_RAW_DATA:
+            if ldi.total_records > 1:
+                check_result = False
+                global_value.logger.error("NVRAM_ATTR_RAW_DATA can not support multiple record.")
+            if ldi.p_default_value != const_value.NVRAM_EF_ZERO_DEFAULT:
+                check_result = False
+                global_value.logger.error("NVRAM_ATTR_RAW_DATA can only use NVRAM_EF_ZERO_DEFAULT.")
+    if not check_result:
+        sys.exit("NVRAM_ATTR_RAW_DATA can not support multiple record ,and can only use NVRAM_EF_ZERO_DEFAULT.")
+
+
+def hash_md5(strs):
+    m = hashlib.md5()
+    m.update(strs.encode(encoding='utf-8'))
+    list_a = list(m.hexdigest())
+    list_re = []
+    for i in range(16):
+        list_re.append(int(list_a[2*i], 16) * 16 + int(list_a[2*i + 1], 16))
+    return list_re
+
+
+def check_lid_hash_key():
+    first_print = True
+    if global_value.macro & const_value.__NVRAM_LID_HASH_CHECK__ and global_value.macro & const_value.__MTK_INTERNAL__:  # __NVRAM_LID_HASH_CHECK__ and __MTK_INTERNAL__
+        for ldi in logical_data_item_table:
+            global_value.logger.debug("check lid: %s hash key: 0x%08x", ldi.str_LID, ldi.hash_key)
+            if ldi.lid & 0xF000 == 0xF000:
+                global_value.logger.debug("internal lid {}, no check!".format(ldi.str_LID))
+                continue
+            if not (ldi.FilePrefix[0] == 'C' and ldi.FilePrefix[1] == 'U'):
+                strbuf = str(ldi.lid) + ";" + ldi.str_LID + ";" + ldi.FilePrefix + ";" + ldi.FileVerno + ";"
+                digest = hash_md5(strbuf)
+                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)
+                hash &= 0xffffffff
+                if hash != ldi.hash_key:
+                    if first_print:
+                        global_value.logger.error(
+                            "Need register LID http://wiki.mediatek.inc/display/NVRAM/How+to+apply+LID+HASH+key")
+                        global_value.logger.error(
+                            "This feature is just internal use. Please set NVRAM_LID_HASH_CHECK = FALSE for customer.")
+                        first_print = False
+                    global_value.logger.error("%s (0x%08x) hash key is not match.", ldi.str_LID, ldi.hash_key)
+                    global_value.logger.error("hash in str:%d;%s;%s;%s;", ldi.lid, ldi.str_LID, ldi.FilePrefix, ldi.FileVerno)
+                    global_value.logger.error("hash out: %x", hash)
+        if not first_print:
+            sys.exit("HASH key check error")
+
+
+def nvram_gen_check_cate_attr_conflicts():
+    check_result = True
+
+    for ldi in logical_data_item_table:
+        for check_cond in nvram_cate_attr_conflict_table:
+            if check_cond[0] == con_type_enum["attr_attr"]:
+                if ((ldi.attr & check_cond[1]) != 0) and ((ldi.attr & (~check_cond[1]) & check_cond[2]) != 0):
+                    check_result = False
+                    global_value.logger.error("LID %s have conflict attributes ", ldi.str_LID)
+            elif check_cond[0] == con_type_enum["cate_attr"]:
+                if ((ldi.category & check_cond[1]) != 0) and ((ldi.attr & check_cond[2]) != 0):
+                    check_result = False
+                    global_value.logger.error("LID %s have conflict attributes with category ", ldi.str_LID)
+            elif check_cond[0] == con_type_enum["cate_cate"]:
+                if ((ldi.category & check_cond[1]) != 0) and ((ldi.category & (~check_cond[1]) & check_cond[2]) != 0):
+                    check_result = False
+                    global_value.logger.error("LID %s have conflict categories ", ldi.str_LID)
+            else:
+                pass
+    if not check_result:
+        global_value.logger.error("Please adjust LID's attributes and/or categories")
+        sys.exit("Please adjust LID's attributes and/or categories")
+
+
+
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/custpackhelper.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/custpackhelper.py
new file mode 100644
index 0000000..4277980
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/custpackhelper.py
@@ -0,0 +1,56 @@
+import os
+
+from .initconfig import global_value
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import printf
+from .initconfig import autogen_open_file
+
+
+def nvram_gen_custpack_table():
+    """ gen file: nvram_custpack_table.c / nvram_custpack_table_lid.c """
+    fd_1 = autogen_open_file(global_value.autogen_path, "nvram_custpack_table.c", "w+")
+    fd_2 = autogen_open_file(global_value.autogen_path, "nvram_custpack_table_lid.c", "w+")
+
+    printf("#if defined(NVRAM_INTERNAL_USE) && !defined(NVRAM_NOT_PRESENT)\n", file=fd_1, end="")
+    printf("/********************************************************\n", file=fd_1, end="")
+    printf(" *  This file is generated automatically by nvram_auto_gen\n", file=fd_1, end="")
+    printf(" *  Please do not modify it here manually\n", file=fd_1, end="")
+    printf(" ***********************************************************/\n", file=fd_1, end="")
+
+    printf("#if defined(NVRAM_LTABLE_C_ONLY)\n", file=fd_2, end="")
+    printf("const custpack_nvram_header custpack_nvram_ptr = \n", file=fd_1, end="")
+    printf("const nvram_custpack_lid_tbl_struct custpack_nvram_lid_tal = \n", file=fd_2, end="")
+    printf("{\n", file=fd_1, end="")
+    printf("{\n", file=fd_2, end="")
+    printf("    0,\n", file=fd_1, end="")
+    printf("    0,\n", file=fd_2, end="")
+    printf("    {\n", file=fd_1, end="")
+    printf("    {\n", file=fd_2, end="")
+
+    start = global_value.NVRAM_EF_START
+    j = 0
+    for i in range(start, len(logical_data_item_table)):
+        ldi = logical_data_item_table[i]
+        if ldi.lid == 0 or ldi.size == 0 or ldi.total_records == 0:
+            continue
+        if ldi.category & const_value.NVRAM_CATEGORY_CUSTPACK:
+            j += 1
+            printf("        %s" % ldi.str_default_value, file=fd_1, end="")
+            printf("        %d" % ldi.lid, file=fd_2, end="")
+            if j != global_value.custpack_total_to_verify:
+                printf(",", file=fd_1, end="")
+                printf(",", file=fd_2, end="")
+            printf("\n", file=fd_1, end="")
+            printf("\n", file=fd_2, end="")
+    printf("    }\n", file=fd_1, end="")
+    printf("    }\n", file=fd_2, end="")
+    printf("};\n", file=fd_1, end="")
+    printf("};\n", file=fd_2, end="")
+    printf("#endif /* NVRAM_INTERNAL_USE && NVRAM_NOT_PRESENT */\n\n", file=fd_1, end="")
+    printf("#endif\n\n", file=fd_2, end="")
+
+    fd_1.close()
+    fd_2.close()
+
+
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_assign_entry.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_assign_entry.py
new file mode 100644
index 0000000..24a7a5f
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_assign_entry.py
@@ -0,0 +1,383 @@
+import sys
+
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import global_value
+from .initconfig import get_checksum_size
+
+
+def adjust_attr_cate_i(ldi):
+    """Do not need multiple attribute if nvram saved on nor flash"""
+    if ldi.total_records < 2 and (
+            ldi.attr & const_value.NVRAM_ATTR_MULTIREC_READ or ldi.attr & const_value.NVRAM_ATTR_MULTI_DEFAULT):
+        global_value.logger.error(
+            "Can't Set the NVRAM_ATTR_MULTIREC_READ or NVRAM_ATTR_MULTI_DEFAULT for the lid with only one record, %d, %s",
+            ldi.lid, ldi.str_LID)
+        sys.exit("Can't Set the NVRAM_ATTR_MULTIREC_READ or NVRAM_ATTR_MULTI_DEFAULT for the lid with only one record")
+    if ldi.p_default_value == const_value.NVRAM_EF_FF_DEFAULT or ldi.p_default_value == const_value.NVRAM_EF_ZERO_DEFAULT:
+        check_result = False
+        if (ldi.attr & const_value.NVRAM_ATTR_GEN_DEFAULT) and not(ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT_L4):
+            if global_value.macro & const_value.__NVRAM_UT_TEST__:
+                if ldi.lid < const_value.NVRAM_EF_NVRAM_UNIT_TEST_LID or ldi.lid > const_value.NVRAM_EF_NVRAM_UNIT_TEST_LID_END:
+                    check_result = True
+                else:
+                    check_result = False
+            else:
+                check_result = True
+        if check_result:
+            global_value.logger.error(
+                "Can't Set the NVRAM_ATTR_GEN_DEFAULT attribute for the lid with Zero of FF default value, %d, %s",
+                ldi.lid, ldi.str_LID)
+            sys.exit("Can't Set the NVRAM_ATTR_GEN_DEFAULT attribute for the lid with Zero of FF default value")
+    if (ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT_L4) and not(ldi.attr & const_value.NVRAM_ATTR_GEN_DEFAULT):
+        global_value.logger.error(
+                "NVRAM_CATEGORY_IMPORTANT_L4 must have NVRAM_ATTR_GEN_DEFAULT attribute!!, %d, %s",
+                ldi.lid, ldi.str_LID)
+        sys.exit("NVRAM_CATEGORY_IMPORTANT_L4 must have NVRAM_ATTR_GEN_DEFAULT attribute!!")
+
+def adjust_attr_cate_ii(ldi):
+    """ MULTIPLE / BACKUP_RAW / BACKUP_FAT are mutually exclusive """
+    if ldi.category & const_value.NVRAM_CATEGORY_CALIBRAT:
+        if ldi.attr & const_value.NVRAM_ATTR_RESERVE_BACKWARD or ldi.attr & const_value.NVRAM_ATTR_MULTIPLE:
+            global_value.logger.error(
+                "Can't Set NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_RESERVE_BACKWARD for Calibrate Lid, %d, %s",
+                ldi.lid, ldi.str_LID)
+            sys.exit("Can't Set NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_RESERVE_BACKWARD for Calibrate Lid")
+        if global_value.macro & const_value.__NVRAM_BACKUP_DISK_FAT__:
+            if ldi.attr & const_value.NVRAM_ATTR_MULTIPLE or ldi.attr & const_value.NVRAM_ATTR_BACKUP_RAW:
+                global_value.logger.error(
+                    "Can't Set the NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_BACKUP_RAW for Calibrate, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit("Can't Set the NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_BACKUP_RAW for Calibrate")
+            if (ldi.attr & const_value.NVRAM_ATTR_BACKUP_FAT) == 0:
+                global_value.logger.error(
+                    "Should set the NVRAM_ATTR_BACKUP_FAT for Calibrate, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit("Should set the NVRAM_ATTR_BACKUP_FAT for Calibrate")
+        elif global_value.macro & const_value.__NVRAM_BACKUP_DISK_RAW__:
+            if ldi.attr & const_value.NVRAM_ATTR_MULTIPLE or ldi.attr & const_value.NVRAM_ATTR_BACKUP_FAT:
+                global_value.logger.error(
+                    "Can't Set the NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_BACKUP_FAT for Calibrate, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit("Can't Set the NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_BACKUP_FAT for Calibrate")
+            if (ldi.attr & const_value.NVRAM_ATTR_BACKUP_RAW) == 0:
+                global_value.logger.error(
+                    "Should set the NVRAM_ATTR_BACKUP_RAW for Calibrate, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit("Should set the NVRAM_ATTR_BACKUP_RAW for Calibrate")
+        else:
+            if (not global_value.macro & const_value.__LOW_COST_SUPPORT_COMMON__) and (
+                    not global_value.macro & const_value.__CCCIFS_SUPPORT__) and (
+                    not global_value.macro & const_value.__FS_RAMDISK__):
+                if (ldi.attr & const_value.NVRAM_ATTR_MULTIPLE) == 0:
+                    global_value.logger.error(
+                        "Should set the NVRAM_ATTR_MULTIPLE for Calibrate under this scenario, %d, %s",
+                        ldi.lid, ldi.str_LID)
+                    sys.exit("Should set the NVRAM_ATTR_MULTIPLE for Calibrate under this scenario")
+            if ldi.attr & const_value.NVRAM_ATTR_BACKUP_RAW or ldi.attr & const_value.NVRAM_ATTR_BACKUP_FAT:
+                global_value.logger.error(
+                    "Can't Set the NVRAM_ATTR_BACKUP_RAW/NVRAM_ATTR_BACKUP_FAT for Calibrate, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit("Can't Set the NVRAM_ATTR_BACKUP_RAW/NVRAM_ATTR_BACKUP_FAT for Calibrate")
+
+
+def adjust_attr_cate_iii(ldi):
+    """just apply to smartphone
+        1: When AP side clean boot, nvram will reset all lid
+        2: When Modem 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 global_value.macro & const_value.__CCCIFS_SUPPORT__:
+        if ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT or ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT_L4:
+            if ldi.attr & const_value.NVRAM_ATTR_RESERVE_BACKWARD:
+                global_value.logger.error(
+                    "Can't Set the NVRAM_ATTR_RESERVE_BACKWARD for Important/Important_L4, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit("Can't Set the NVRAM_ATTR_RESERVE_BACKWARD for Important/Important_L4")
+            if (ldi.attr & const_value.NVRAM_ATTR_COMMITTED) == 0:
+                global_value.logger.error(
+                    "Suggest Set the NVRAM_ATTR_COMMITTED for Important/Important_L4, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit("Suggest Set the NVRAM_ATTR_COMMITTED for Important/Important_L4")
+
+
+def adjust_attr_cate_iv(ldi):
+    """
+    OTP category cannot use with many attribute together. Because it cannot be reset
+    OTP category also cannot use with other category together
+    """
+    if global_value.macro & const_value.__NVRAM_OTP__:
+        if ldi.category & const_value.NVRAM_CATEGORY_OTP:
+            if ldi.attr & const_value.NVRAM_ATTR_WRITEPROTECT or ldi.attr & const_value.NVRAM_ATTR_MULTIPLE or ldi.attr & const_value.NVRAM_ATTR_MSP or ldi.attr & const_value.NVRAM_ATTR_OTA_RESET:
+                global_value.logger.error(
+                    "Can't Set NVRAM_ATTR_WRITEPROTECT/NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_MSP/NVRAM_ATTR_OTA_RESET for OTP, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit(
+                    "Can't Set NVRAM_ATTR_WRITEPROTECT/NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_MSP/NVRAM_ATTR_OTA_RESET for OTP")
+
+
+def adjust_attr_cate_v(ldi):
+    """ Add pseudo merge attribute """
+    
+    nvram_checksum_size = get_checksum_size(ldi)
+    
+    if global_value.macro & const_value.__NVRAM_PSEUDO_MERGE__:
+        if (ldi.attr & const_value.NVRAM_ATTR_PACKAGE) == 0:
+            check_result_1 = False
+            check_result_2 = False
+            check_result_3 = False
+            if (not ldi.category & const_value.NVRAM_CATEGORY_INTERNAL) and \
+                    (not ldi.category & const_value.NVRAM_CATEGORY_SECUPACK) and \
+                    (not ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT) and \
+                    (not ldi.category & const_value.NVRAM_CATEGORY_CALIBRAT) and \
+                    ((ldi.size + nvram_checksum_size) * ldi.total_records < const_value.NVRAM_CLUSTER_SIZE):
+                check_result_1 = True
+            if global_value.macro & const_value.__NVRAM_CUSTOM_SENSITIVE__:
+                if not ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE:
+                    check_result_2 = True
+            else:
+                check_result_2 = True
+            if global_value.macro & const_value.__NVRAM_CUSTOM_DISK__:
+                if not ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_DISK:
+                    check_result_3 = True
+            else:
+                check_result_3 = True
+            if check_result_1 and check_result_2 and check_result_3:
+                global_value.logger.error(
+                    "Should set the NVRAM_ATTR_PACKAGE for this lid, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit(
+                    "Should set the NVRAM_ATTR_PACKAGE for this lid")
+        if ldi.attr & const_value.NVRAM_ATTR_PACKAGE:
+            ldi.description = "null"
+            if ldi.attr & const_value.NVRAM_ATTR_MULTIPLE or ldi.attr & const_value.NVRAM_ATTR_MSP:
+                global_value.logger.error(
+                    "Can't Set NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_MSP for PACKAGE Lid, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit(
+                    "Can't Set NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_MSP for PACKAGE Lid")
+
+
+def adjust_attr_cate_vi(ldi):
+    """ Add MSP, confidential, multiple with secupack item"""
+    if ldi.category & const_value.NVRAM_CATEGORY_SECUPACK:
+        check_result = False
+        if not (ldi.attr & const_value.NVRAM_ATTR_CONFIDENTIAL):
+            check_result = True
+        if global_value.macro & const_value.__NVRAM_BIND_TO_CHIP_CIPHER__ and (
+                not ldi.attr & const_value.NVRAM_ATTR_MSP):
+            check_result = True
+        if check_result:
+            global_value.logger.error(
+                "Should set the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL, %d, %s",
+                ldi.lid, ldi.str_LID)
+            sys.exit(
+                "Should set the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL")
+
+
+def adjust_attr_cate_vii(ldi):
+    """ Add MSP, confidential, multiple with custom sensitive data
+        Simulation/Palladium/FPGA remove NVRAM_ATTR_GEN_DEFAULT
+    """
+    if global_value.macro & const_value.__NVRAM_CUSTOM_SENSITIVE__:
+        if ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE:
+            if (not ldi.attr & const_value.NVRAM_ATTR_MSP) or (not ldi.attr & const_value.NVRAM_ATTR_CONFIDENTIAL) or (
+                    not ldi.attr & const_value.NVRAM_ATTR_MULTIPLE):
+                global_value.logger.error(
+                    "Should set the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL/NVRAM_ATTR_MULTIPLE, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit(
+                    "Should set the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL/NVRAM_ATTR_MULTIPLE")
+    if global_value.macro & (const_value._SIMULATION | const_value.__PALLADIUM__ | const_value.__FPGA__):
+        if not ldi.category & const_value.NVRAM_CATEGORY_INTERNAL:
+            ldi.attr &= ~const_value.NVRAM_ATTR_GEN_DEFAULT
+
+
+def adjust_attr_cate_viii(ldi):
+    """ remove all attribute if the data is in custom disk"""
+    if global_value.macro & const_value.__NVRAM_CUSTOM_DISK__:
+        if ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_DISK:
+            if ldi.attr != const_value.NVRAM_ATTR_AVERAGE:
+                global_value.logger.error(
+                    "Can't set other attribute except NVRAM_ATTR_AVERAGE, %d, %s",
+                    ldi.lid, ldi.str_LID)
+                sys.exit(
+                    "Can't set other attribute except NVRAM_ATTR_AVERAGE")
+
+
+def adjust_attr_cate_x(ldi):
+    """
+        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
+    """
+    pass
+
+
+def adjust_attr_cate_xi(ldi):
+    """ Put Internal, Calibration, Important data into SDS"""
+    if global_value.macro & const_value.__NVRAM_SECURE_DATA_STORAGE__:
+        if ldi.category & (
+                const_value.NVRAM_CATEGORY_INTERNAL | const_value.NVRAM_CATEGORY_CALIBRAT | const_value.NVRAM_CATEGORY_IMPORTANT | const_value.NVRAM_CATEGORY_IMPORTANT_L4):
+            ldi.category |= const_value.NVRAM_CATEGORY_BACKUP_SDS
+            ldi.attr &= ~const_value.NVRAM_ATTR_MULTIPLE
+            ldi.attr &= ~const_value.NVRAM_ATTR_RING
+            ldi.attr &= ~const_value.NVRAM_ATTR_PACKAGE
+            ldi.attr &= ~const_value.NVRAM_ATTR_BACKUP_FAT
+            ldi.attr &= ~const_value.NVRAM_ATTR_BACKUP_RAW
+
+
+def check_item_data_i(ldi):
+    """ cannot put the data into two categories that are mutually exclusive"""
+    check_result = False
+
+    if global_value.macro & const_value.__NVRAM_CUSTOM_SENSITIVE__:
+        if (ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE) and (
+                ldi.category & const_value.NVRAM_CATEGORY_CALIBRAT):
+            check_result = True
+        elif (ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE) and (
+                ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT):
+            check_result = True
+        elif (ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE) and (
+                ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT_L4):
+            check_result = True
+        elif (ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE) and (
+                ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT_L1):
+            check_result = True
+    if global_value.macro & const_value.__NVRAM_CUSTOM_DISK__:
+        if (ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_DISK) and (
+                ldi.category & const_value.NVRAM_CATEGORY_INTERNAL):
+            check_result = True
+        elif (ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_DISK) and (
+                ldi.category & const_value.NVRAM_CATEGORY_CALIBRAT):
+            check_result = True
+        elif (ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_DISK) and (
+                ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT):
+            check_result = True
+        elif (ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_DISK) and (
+                ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT_L4):
+            check_result = True
+        elif (ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_DISK) and (
+                ldi.category & const_value.NVRAM_CATEGORY_IMPORTANT_L1):
+            check_result = True
+    if (global_value.macro & const_value.__NVRAM_CUSTOM_SENSITIVE__) and (
+            global_value.macro & const_value.__NVRAM_CUSTOM_DISK__):
+        if (ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE) and (
+                ldi.category & const_value.NVRAM_CATEGORY_CUSTOM_DISK):
+            check_result = True
+    if check_result:
+        global_value.logger.error(
+            "Category internal & calibrat & important & sensitive can't be used at the same time!, %d, %s",
+            ldi.lid, ldi.str_LID)
+        sys.exit(
+            "Category internal & calibrat & important & sensitive can't be used at the same time!")
+
+
+def check_item_data_ii(ldi):
+    """ cannot put the sds data with custom"""
+    nvram_checksum_size = get_checksum_size(ldi)
+    
+    if (global_value.macro & const_value.__NVRAM_SECURE_DATA_STORAGE__) and (
+            ldi.category & const_value.NVRAM_CATEGORY_BACKUP_SDS):
+        if ldi.category & (
+                const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE | const_value.NVRAM_CATEGORY_CUSTOM_DISK | const_value.NVRAM_CATEGORY_OTP):
+            global_value.logger.error(
+                "Sds use with wrong category LID:%s Desc:%s category %d",
+                ldi.str_LID, ldi.str_LID, ldi.category)
+            sys.exit(
+                "Sds use with wrong category")
+        if ldi.attr & (
+                const_value.NVRAM_ATTR_MULTIPLE | const_value.NVRAM_ATTR_RING | const_value.NVRAM_ATTR_PACKAGE | const_value.NVRAM_ATTR_BACKUP_FAT | const_value.NVRAM_ATTR_BACKUP_RAW):
+            global_value.logger.error(
+                "Sds use with wrong attribute LID:%s Desc:%s attribute %d",
+                ldi.str_LID, ldi.str_LID, ldi.attr)
+            sys.exit(
+                "Sds use with wrong attribute LID")
+        if (global_value.macro & const_value.__NVRAM_BIND_TO_CHIP_CIPHER__) and (ldi.attr & const_value.NVRAM_ATTR_MSP):
+            section_size = ldi.size + nvram_checksum_size + (
+                    (~(ldi.size + nvram_checksum_size) + 1) & (const_value.NVRAM_MSP_ALIGNMENT - 1))
+        else:
+            section_size = ldi.size + nvram_checksum_size
+
+        if section_size * ldi.total_records > const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SIZE:
+            global_value.logger.error(
+                "Data is too large to put into sds LID:%s Desc:%s %d %d",
+                ldi.str_LID, ldi.str_LID, ldi.size, ldi.total_records)
+            sys.exit(
+                "Data is too large to put into sds")
+
+
+def check_item_data_iii(ldi):
+    """ cannot use zero default or ff default with multi default"""
+    if ldi.attr & const_value.NVRAM_ATTR_MULTI_DEFAULT:
+        if ldi.str_default_value == "NVRAM_EF_ZERO_DEFAULT" or ldi.str_default_value == "NVRAM_EF_FF_DEFAULT":
+            global_value.logger.error(
+                "Cannot set ZERO_DEFAULT or FF_DEFAULT with multi_default!, %d, %s",
+                ldi.lid, ldi.str_LID)
+            sys.exit(
+                "Cannot set ZERO_DEFAULT or FF_DEFAULT with multi_default!")
+
+
+def check_item_data_iv(ldi):
+    """ The record size cannot bigger than the biggest control buffer"""
+    
+    nvram_checksum_size = get_checksum_size(ldi)
+    
+    if not global_value.macro & const_value.__NVRAM_LARGE_RECORD_SIZE__:
+        if (global_value.macro & const_value.__NVRAM_BIND_TO_CHIP_CIPHER__) and (ldi.attr & const_value.NVRAM_ATTR_MSP):
+            section_size = ldi.size + nvram_checksum_size + (
+                    (~(ldi.size + nvram_checksum_size) + 1) & (const_value.NVRAM_MSP_ALIGNMENT - 1))
+        else:
+            section_size = ldi.size + nvram_checksum_size
+
+        if section_size > const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SIZE:
+            global_value.logger.error(
+                "LID Size is too big, %d, %s",
+                ldi.lid, ldi.str_LID)
+            sys.exit(
+                "LID Size is too big")
+
+
+def check_item_data_v(ldi):
+    """ Items in custpack cannot use zero default or ff default as the default value"""
+    if ldi.category & const_value.NVRAM_CATEGORY_CUSTPACK:
+        if ldi.str_default_value == "NVRAM_EF_ZERO_DEFAULT" or ldi.str_default_value == "NVRAM_EF_FF_DEFAULT":
+            global_value.logger.error(
+                "Cannot set ZERO_DEFAULT or FF_DEFAULT with custpack!, %d, %s",
+                ldi.lid, ldi.str_LID)
+            sys.exit(
+                "Cannot set ZERO_DEFAULT or FF_DEFAULT with custpack!")
+
+
+def check_item_data_vi(ldi):
+    """ Build error check: CALIBRAT LID should not have NVRAM_ATTR_OTA_RESET attribute"""
+    if (ldi.category & const_value.NVRAM_CATEGORY_CALIBRAT) and (ldi.attr & const_value.NVRAM_ATTR_OTA_RESET):
+        global_value.logger.error(
+            "CALIBRAT LID should not have NVRAM_ATTR_OTA_RESET attribute!, %d, %s",
+            ldi.lid, ldi.str_LID)
+        sys.exit(
+            "CALIBRAT LID should not have NVRAM_ATTR_OTA_RESET attribute!")
+
+
+def nvram_gen_assign_entry():
+    for ldi in logical_data_item_table:
+        # Tool check begin:
+        # nvram_pre_gen.pl check if it is same asnvram_assign_table_entry() and nvram_gen_assign_entry()
+        adjust_attr_cate_i(ldi)
+        adjust_attr_cate_ii(ldi)
+        adjust_attr_cate_iii(ldi)
+        adjust_attr_cate_iv(ldi)
+        adjust_attr_cate_v(ldi)
+        adjust_attr_cate_vi(ldi)
+        adjust_attr_cate_vii(ldi)
+        adjust_attr_cate_viii(ldi)
+        adjust_attr_cate_xi(ldi)
+        # Tool check end: nvram_pre_gen.pl
+
+        check_item_data_i(ldi)
+        check_item_data_ii(ldi)
+        check_item_data_iii(ldi)
+        check_item_data_iv(ldi)
+        check_item_data_v(ldi)
+        check_item_data_vi(ldi)
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_cache_info.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_cache_info.py
new file mode 100644
index 0000000..4eddc60
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_cache_info.py
@@ -0,0 +1,143 @@
+import os
+import struct
+import re
+
+
+from .initconfig import global_value
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import COPYRIGHTS_HEADER
+from .initconfig import printf
+from .initconfig import autogen_open_file
+
+def parse_noncache_list():
+    noncache_list = []
+    if global_value.macro & const_value.__NVRAM_PARTIAL_CACHE__:
+        noncache_list_start = 0
+        fd = autogen_open_file("service/nvram/src", "nvram_cache_white_list.c", "r")
+
+        for each_line in fd:
+            """ remove whitespace"""
+            if each_line.isspace():
+                continue
+            if re.search("kal_uint32 nvram_lid_noncache_list\[\]= \{", each_line):
+                noncache_list_start = 1
+                continue
+            if noncache_list_start != 1:
+                continue
+            if re.search("\}\;", each_line) and (noncache_list_start == 1):
+                break
+            strs = each_line.strip()  # clear tail character ('\n' ' ' '\t' '\r')
+            strlist = strs.split(',')
+            global_value.logger.info("noncache_list_strlist: %s" % strs)
+            noncache_list.append(int(strlist[0]))
+    return noncache_list
+
+def cache_header_generator(fd, dirty_bit_table_length, cache_data_offset, nvram_gen_total_cache_lid):
+    """ write header array"""
+    cache_lid_num = nvram_gen_total_cache_lid
+    table_index_offset = struct.calcsize('8I') # sizeof(nvram_lid_cache_header)
+    table_index_size = struct.calcsize('H6I36c')*nvram_gen_total_cache_lid  # sizeof(nvram_lid_cache_table_struct)
+    data_base_offset = table_index_offset + table_index_size
+    data_base_offset = ((data_base_offset + const_value.SHARE_MEM_64BYTE_ALIGN - 1)//const_value.SHARE_MEM_64BYTE_ALIGN) * const_value.SHARE_MEM_64BYTE_ALIGN
+    dirty_mapping_offset = data_base_offset
+    dirty_mapping_size = ((dirty_bit_table_length + const_value.SHARE_MEM_64BYTE_ALIGN - 1)//const_value.SHARE_MEM_64BYTE_ALIGN) * const_value.SHARE_MEM_64BYTE_ALIGN
+    data_base_offset += dirty_mapping_size
+    valid_mapping_offset = data_base_offset
+
+    data_base_offset += dirty_mapping_size
+    cache_table_offset = data_base_offset
+    cache_table_size = cache_data_offset
+
+    printf("nvram_lid_cache_header cache_info_header = {\n", file=fd, end="")
+    printf("\t%u,\n" % cache_lid_num, file=fd, end="")
+    printf("\t%u,\n" % table_index_offset, file=fd, end="")
+    printf("\t%u,\n" % table_index_size, file=fd, end="")
+    printf("\t%u,\n" % dirty_mapping_offset, file=fd, end="")
+    printf("\t%u,\n" % valid_mapping_offset, file=fd, end="")
+    printf("\t%u,\n" % dirty_mapping_size, file=fd, end="")
+    printf("\t%u,\n" % cache_table_offset, file=fd, end="")
+    printf("\t%u\n" % cache_table_size, file=fd, end="")
+    printf("};\n\n", file=fd, end="")
+    need_shm_size = cache_table_offset + cache_table_size
+    if need_shm_size > const_value.SHARE_MEMORY_SIZE:
+        global_value.logger.error("Error: Please contact NVRAM owner, the NV Cache Share Memory Size Too small. currently total LID size is: 0x%x.\n", need_shm_size)
+        sys.exit(-1)
+
+
+def nvram_gen_cache_info():
+    ''' gen file : nvram_cache_info.c / nvram_cache_info.h '''
+    # Local Variables
+    cache_data_offset = 0
+    dirty_bit_table_offset = 0
+    dirty_bit_table_length = 0
+    nvram_gen_total_cache_lid = 0
+
+    fd = autogen_open_file(global_value.autogen_path, "nvram_cache_info.c", "w+")
+
+    printf(COPYRIGHTS_HEADER % "nvram_cache_info.c", file=fd, end="")
+
+    printf("#include \"nvram_cache_info.h\"\n", file=fd, end="")
+    printf("\n", file=fd, end="")
+    printf("nvram_lid_cache_table_struct cache_info_table[] = {\n", file=fd, end="")
+
+    noncache_list = parse_noncache_list()
+
+    for item in logical_data_item_table:
+        if global_value.macro & const_value.__NVRAM_PARTIAL_CACHE__:
+            if item.lid in noncache_list:
+                continue
+        lid = item.lid
+        total_records = item.total_records
+
+        cache_offset = cache_data_offset
+        
+        if item.attr & const_value.NVRAM_ATTR_CHKSUM_INTEGRATE:
+            global_value.logger.info("checksum integrate: lid: %s", item.str_LID)
+        onefilesize = item.FileSize
+        
+        file_length = onefilesize
+        cache_data_offset += ((file_length+const_value.SHARE_MEM_64BYTE_ALIGN-1)//const_value.SHARE_MEM_64BYTE_ALIGN)*const_value.SHARE_MEM_64BYTE_ALIGN
+        dirty_offset = dirty_bit_table_offset
+        valid_offset = dirty_bit_table_offset
+        dirty_bit_table_offset += ((total_records + 1 + const_value.DIRTY_BLOCK_SIZE - 1)//const_value.DIRTY_BLOCK_SIZE)*const_value.DIRTY_4BYTE_ALIGN
+        full_path = item.FullPath
+
+        printf("\t{\n", file=fd, end="")
+        printf("\t\t%u,\n" % lid, file=fd, end="")
+        printf("\t\t%u,\n" % 0, file=fd, end="")
+        printf("\t\t%u,\n" % total_records, file=fd, end="")
+        printf("\t\t%u,\n" % file_length, file=fd, end="")
+        printf("\t\t%u,\n" % cache_offset, file=fd, end="")
+        printf("\t\t%u,\n" % dirty_offset, file=fd, end="")
+        printf("\t\t%u,\n" % valid_offset, file=fd, end="")
+        printf("\t\t\"%s\"\n" % full_path, file=fd, end="")
+        printf("\t},\n", file=fd, end="")
+        nvram_gen_total_cache_lid += 1
+    printf("};\n", file=fd, end="")
+    dirty_bit_table_length = dirty_bit_table_offset
+
+    # write header array
+    cache_header_generator(fd, dirty_bit_table_length, cache_data_offset, nvram_gen_total_cache_lid)
+
+    fd.close()
+
+    # write nvram_cache_info.h
+    fd = autogen_open_file(global_value.autogen_path, "nvram_cache_info.h", "w+")
+    printf(COPYRIGHTS_HEADER % "nvram_auto_gen/nvram_cache_info.h", file=fd, end="")
+    printf("#ifndef NVRAM_CACHE_INFO_H\n", file=fd, end="")
+    printf("#define NVRAM_CACHE_INFO_H\n", file=fd, end="")
+    printf("#include \"nvram_cache.h\"\n", file=fd, end="")
+    printf("#include \"nvram_enums.h\"\n", file=fd, end="")
+    printf("#include \"kal_general_types.h\"\n\n", file=fd, end="")
+    printf("extern nvram_lid_cache_table_struct cache_info_table[];\n", file=fd, end="")
+    printf("extern nvram_lid_cache_header cache_info_header;\n\n", file=fd, end="")
+    printf("#endif /*NVRAM_CACHE_INFO_H*/\n", file=fd, end="")
+    fd.close()
+
+
+
+
+
+
+
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_cat_file.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_cat_file.py
new file mode 100644
index 0000000..7819174
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_cat_file.py
@@ -0,0 +1,62 @@
+import os
+
+from .initconfig import global_value
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import printf
+from .initconfig import autogen_open_file
+
+
+def nvram_gen_cat_xml():
+    """ gen file : custom_nvram_lid_cat.xml """
+    fd = autogen_open_file(global_value.autogen_path, "custom_nvram_lid_cat.xml", "w+")
+    printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", file=fd, end="")
+    printf("<APP>\n", file=fd, end="")
+    for ldi in logical_data_item_table:
+        if ldi.lid == 0 or ldi.size == 0 or ldi.total_records == 0:
+            continue
+        printf("    <NVRAMITEM id=\"%s\"" % ldi.str_LID, file=fd, end="")
+        printf(" prefix=\"%s\"" % ldi.FilePrefix, file=fd, end="")
+        printf(" version=\"%s\"" % ldi.FileVerno, file=fd, end="")
+        printf(" record_size=\"%d\"" % ldi.size, file=fd, end="")
+        printf(" total_record=\"%d\"" % ldi.total_records, file=fd, end="")
+        printf(" lid_enum=\"%d\"" % ldi.lid, file=fd, end="")
+        printf(" category=\"0x%x\"" % ldi.category, file=fd, end="")
+        printf(" attribute=\"0x%x\">\n" % ldi.attr, file=fd, end="")
+        if ldi.category & const_value.NVRAM_CATEGORY_FUNC_DEFAULT:
+            printf("        <DEFAULT_VALUE defaultByteFill=\"%s()\"></DEFAULT_VALUE>\n" % ldi.str_default_value, file=fd, end="")
+        elif ldi.p_default_value == const_value.NVRAM_EF_FF_DEFAULT:
+            printf("        <DEFAULT_VALUE defaultByteFill=\"0xFF\"></DEFAULT_VALUE>\n", file=fd, end="")
+        elif ldi.p_default_value == const_value.NVRAM_EF_ZERO_DEFAULT:
+            printf("        <DEFAULT_VALUE defaultByteFill=\"0x00\"></DEFAULT_VALUE>\n", file=fd, end="")
+        elif ldi.p_default_value == const_value.NVRAM_EF_SPECIAL_DEFAULT:
+            printf("        <DEFAULT_VALUE defaultByteFill=\"0x00\"></DEFAULT_VALUE>\n", file=fd, end="")
+        else:
+            if ldi.attr & const_value.NVRAM_ATTR_MULTI_DEFAULT:
+                printf("        <DEFAULT_VALUE isMultiple=\"TRUE\"> \n", file=fd, end="")
+            else:
+                printf("        <DEFAULT_VALUE> \n", file=fd, end="")
+            for i in range(ldi.default_value_len):
+                if ldi.default_value_len == 1:
+                    printf("            [0x%02X]\n        </DEFAULT_VALUE>\n" % ldi.default_value[i], file=fd, end="")
+                elif i == 0:
+                    printf("            [0x%02X," % ldi.default_value[i], file=fd, end="")
+                elif i == (ldi.default_value_len - 1):
+                    printf(" 0x%02X]\n        </DEFAULT_VALUE>\n" % ldi.default_value[i], file=fd, end="")
+                elif (i & 0x0F) == 0x0F:
+                    printf(" 0x%02X,\n" % ldi.default_value[i], file=fd, end="")
+                elif (i & 0x0F) == 0x00:
+                    printf("             0x%02X," % ldi.default_value[i], file=fd, end="")
+                else:
+                    printf(" 0x%02X," % ldi.default_value[i], file=fd, end="")
+        printf("        <DESCRIPTION> %s </DESCRIPTION>\n" % ldi.str_LID, file=fd, end="")
+        printf("    </NVRAMITEM>\n", file=fd, end="")
+    printf("</APP>\n", file=fd, end="")
+    fd.close()
+
+
+
+
+
+
+
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_lid_information.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_lid_information.py
new file mode 100644
index 0000000..a2d673a
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_lid_information.py
@@ -0,0 +1,174 @@
+import os
+import struct
+import sys
+import json
+
+from .initconfig import global_value
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import printf, get_checksum_size
+from .initconfig import autogen_open_file, nvram_algo_type_str
+from .initconfig import nvram_is_category_in_bin_region, nvram_is_category_factory_reset
+
+
+def nvram_gen_info_size_log():
+    ''' gen file : ~nvram_lid_information.log / ~nvram_lid_size.log'''
+    estimate_size = 0
+    estimate_fs_size = 0
+    bin_region_size = 0
+    protect_size = 0
+    # ------------------------------
+    sum = 0
+    nvram_auto_package_num = 0
+    nvram_auto_pack_file_offset = struct.calcsize("6IH") + 8
+    fake_lid = len(logical_data_item_table)
+    lid_detail_info = {"lids":[], "chksum_info":{}}
+    # ------------------------------
+
+    logOfTools = autogen_open_file(global_value.autogen_path, "~nvram_lid_information.log", "w+")
+    logOfSize = autogen_open_file(global_value.autogen_path, "~nvram_lid_size.log", "w+")
+
+    printf("-----------------------------------------------------------------------"
+          "-----------------------------------------------------------------------\n",
+          file=logOfTools, end="")
+    printf("-----------------------------------------------------------------------"
+          "-----------------------------------------------------------------------\n",
+          file=logOfTools, end="")
+    printf("%4s    %55s    %10s    %10s    %11s  %10s   %10s\n" %("LID", "LID(String)", "Filename", "Verno", "Description", "Category", "Attribute"),
+          file=logOfTools, end="")
+    printf("-----------------------------------------------------------------------"
+          "-----------------------------------------------------------------------\n",
+          file=logOfTools, end="")
+    printf("00000       long:%d,char*:%d,padding:%d                     NVRAM_PADDING_TEST\n" %(global_value.nvram_long_length,
+        global_value.nvram_ptr_length, global_value.nvram_padding_length//3), file=logOfSize, end="")
+    printf("--------------------------------------------------------------------------\n", file=logOfSize, end="")
+    # ------------------------------
+    if global_value.macro & const_value.__NVRAM_PSEUDO_MERGE__: # not run
+        # logOfSize_Package = open(os.path.join(global_value.path, "nvram_auto_gen", "nvram_lid_size_merge.log"), "w+")
+        logOfSize_Package = autogen_open_file(global_value.autogen_path, "nvram_lid_size_merge.log", "w+")
+        printf("%4s   %10s    %10s    %10s    %10s    %10s    %10s\n" % (
+        "ldi->LID", "fileprefix", "onefilesize", "oneLIDsize", "single_num", "single_offset", "file_size"),
+              file=logOfSize_Package, end="")
+    # ------------------------------
+    for ldi in logical_data_item_table:
+        if ldi.lid == 0 or ldi.size == 0 or ldi.total_records == 0:
+            continue
+
+        if global_value.macro & const_value.__NVRAM_PSEUDO_MERGE__: # not run
+            sum += 1
+        
+        
+        nvram_checksum_size = get_checksum_size(ldi)
+            
+        
+        # calculate onefilesize not shout CHKSUM_INTEGRATE
+        if (ldi.attr & const_value.NVRAM_ATTR_CONFIDENTIAL) or (ldi.attr & const_value.NVRAM_ATTR_MSP and global_value.macro & const_value.__NVRAM_BIND_TO_CHIP_CIPHER__):
+            remainLen = (~(ldi.size + nvram_checksum_size) + 1) & (const_value.NVRAM_MSP_ALIGNMENT - 1)
+            onefilesize = (
+                                      ldi.size + nvram_checksum_size + remainLen) * ldi.total_records + const_value.NVRAM_LDI_HEADER_SIZE
+        else:
+            onefilesize = (ldi.size + nvram_checksum_size) * ldi.total_records + const_value.NVRAM_LDI_HEADER_SIZE
+        
+        onefilefssize = (ldi.FileSize + const_value.FS_PAGE_SIZE - 1)//const_value.FS_PAGE_SIZE * const_value.FS_PAGE_SIZE
+        if onefilesize :
+            # ------------------------------
+            if global_value.macro & const_value.__NVRAM_PSEUDO_MERGE__: # not run
+                if ldi.attr & const_value.NVRAM_ATTR_PACKAGE:
+                    printf("%4d    %55s    %10s    %10s    %11s    0x%08x  0x%08x\n" % (ldi.lid, ldi.str_LID, "PACK", "LID",
+                    ldi.description, ldi.category, ldi.attr), file=logOfTools, end="")
+
+                    nvram_auto_package_num += 1
+                    printf("%40s" % ldi.description, file=logOfSize_Package, end="")
+                    ldi.description = nvram_auto_pack_file_offset
+                    nvram_auto_pack_file_offset += onefilefssize
+                    printf("%4s   %10s    %10s    %10s    %10s    %10s    %10s\n" % (ldi.lid, ldi.FilePrefix, onefilesize, ldi.size,
+                    nvram_auto_package_num, ldi.description, nvram_auto_pack_file_offset), file=logOfSize_Package, end="")
+                    if ldi.category & const_value.NVRAM_CATEGORY_CUSTPACK:
+                        custpack = "CUSTPACK"
+                    else:
+                        custpack = ""
+                    printf("%4d%10d%60s%20s\n" % (ldi.lid, 0, ldi.str_LID, custpack), file=logOfSize, end="")
+                    continue
+            # ------------------------------
+            estimate_size += ldi.FileSize
+            estimate_fs_size += onefilefssize
+            if ldi.category & const_value.NVRAM_CATEGORY_CUSTPACK:
+                custpack = "CUSTPACK"
+            else:
+                custpack = ""
+            printf("%4d%10d%60s%20s\n" %(ldi.lid, onefilesize, ldi.str_LID, custpack), file=logOfSize, end="")
+            if ldi.attr & const_value.NVRAM_ATTR_MULTIPLE:
+                estimate_size += ldi.FileSize
+                estimate_fs_size += onefilefssize
+                printf("%4d%10d%60s%20s\n" % (ldi.lid, onefilesize, ldi.str_LID, custpack), file=logOfSize, end="")
+            if nvram_is_category_in_bin_region(ldi.category):
+                bin_region_size += onefilefssize
+                if ldi.attr & const_value.NVRAM_ATTR_MULTIPLE:
+                    bin_region_size += onefilefssize
+            if not nvram_is_category_factory_reset(ldi.category):
+                protect_size += onefilefssize
+
+            printf("%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), file=logOfTools, end="")
+            lid_detail_info["lids"].append({"enum": ldi.lid, "str_LID":ldi.str_LID, "file_prefix":ldi.FilePrefix, "verno":ldi.FileVerno,
+                    "description":ldi.description, "category":ldi.category, "attr":ldi.attr, "size":onefilesize})
+    # ------------------------------
+    if global_value.macro & const_value.__NVRAM_VENDOR_SUPPORT__:
+        printf("%4d%10d%60s\n" % (len(logical_data_item_table), 1024*100, "NVRAM_EF_VENDOR_REMAIN_SPACE_LID"), file=logOfSize, end="")
+    if global_value.macro & const_value.__NVRAM_PSEUDO_MERGE__:  # not run
+        fake_lid = len(logical_data_item_table)
+        if global_value.macro & const_value.__NVRAM_VENDOR_SUPPORT__:
+            fake_lid += 1
+        printf("%4d%10d%40s\n" % (fake_lid, nvram_auto_pack_file_offset, "Package file size"),
+              file=logOfSize, end="")
+        printf("%4d%10d%40s\n" % (fake_lid+1, nvram_auto_package_num*(struct.calcsize("2IH8ss")+2), "Info file A"),
+              file=logOfSize, end="")
+        printf("%4d%10d%40s\n" % (fake_lid+2, nvram_auto_package_num*(struct.calcsize("2IH8ss")+2), "Info file B"),
+              file=logOfSize, end="")
+        printf("%4d%10d%40s\n" % (fake_lid+3, 3*512, "Extra size"),
+              file=logOfSize, end="")
+    # ------------------------------
+
+    printf("--------------------------------------------------------------------------\n", file=logOfSize, end="")
+    printf("-----------------------------------------------------------------------"
+          "---------------------\n",
+          file=logOfTools, end="")
+    if global_value.macro & const_value.__NV_CHKSUM_ENHANCE__:
+        printf("enhance_algo_size=%d\n" % global_value.enhance_size, file=logOfTools, end="")
+        printf("enhance_algo_type=%d\n" % global_value.enhance_type, file=logOfTools, end="")
+        printf("default_algo_size=%d\n" % global_value.default_size, file=logOfTools, end="")
+        printf("default_algo_type=%d\n" % global_value.default_type, file=logOfTools, end="")
+        lid_detail_info["chksum_info"] = {"enhance_algo_size":global_value.enhance_size, "enhance_algo_type":global_value.enhance_type,
+                    "default_algo_size": global_value.default_size, "default_algo_type":global_value.default_type}
+    
+    if global_value.macro & const_value.__NVRAM_COMPRESS_SUPPORT__:
+        printf("NVRAM_COMPRESS=1\n", file=logOfSize, end="")
+    else:
+        printf("NVRAM_COMPRESS=0\n", file=logOfSize, end="")
+
+    printf("NVRAM_ESTIMATE_SIZE=%d\n" % estimate_size, file=logOfSize, end="")
+    printf("NVRAM_ESTIMATE_FS_SIZE=%d\n" % estimate_fs_size, file=logOfSize, end="")
+    printf("bin_region_size=%d\n" % bin_region_size, file=logOfSize, end="")
+    printf("protect_size=%d\n" % protect_size, file=logOfSize, end="")
+    lid_detail_info["total_size"] = estimate_size
+    lid_detail_info["total_fs_size"] = estimate_fs_size
+    
+    if global_value.macro & const_value.__FS_RAMDISK__:
+        printf("RAMDISK_SIZE=%d\n" % const_value.RAM_FS_SIZE, file=logOfSize, end="")
+        lid_detail_info["ramdisk_size"] = const_value.RAM_FS_SIZE
+    if global_value.macro & const_value.__NVRAM_PSEUDO_MERGE__:  # not run
+        logOfSize_Package.close()
+    logOfTools.close()
+    logOfSize.close()
+    # write json
+    with autogen_open_file(global_value.autogen_path, "~nv_lid_detail_info.json", "w") as fh:
+        json.dump(lid_detail_info, fh)
+    if global_value.macro & const_value.__FS_RAMDISK__:
+        if estimate_fs_size > const_value.RAM_FS_SIZE:
+            global_value.logger.error("RAMDISK size is not enough.")
+            global_value.logger.error("NVRAM_ESTIMATE_FS_SIZE=%d", estimate_fs_size)
+            global_value.logger.error("RAMDISK_SIZE=%d", const_value.RAM_FS_SIZE)
+
+            sys.exit("estimate_fs_size > RAMDISK_SIZE")
+
+
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_statistic.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_statistic.py
new file mode 100644
index 0000000..38c6fa8
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/gen_statistic.py
@@ -0,0 +1,36 @@
+import os
+
+from .initconfig import global_value
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import COPYRIGHTS_HEADER
+from .initconfig import printf
+from .initconfig import autogen_open_file
+
+
+def nvram_gen_statistic():
+    ''' gen file: nvram_lid_statistic_bak.h'''
+    fd = autogen_open_file(global_value.autogen_path, "nvram_lid_statistics_bak.h", "w+")
+    printf(COPYRIGHTS_HEADER % "nvram_lid_statistics_bak.h", file=fd, end="")
+    printf("#ifndef NVRAM_LID_STATISTIC_H\n", file=fd, end="")
+    printf("#define NVRAM_LID_STATISTIC_H\n", file=fd, end="")
+
+    if global_value.macro & const_value.__NVRAM_OTP__:  # __NVRAM_OTP__
+        printf("#define NVRAM_OTP_SIZE    %d\n" % global_value.otp_size_to_verify, file=fd, end="")
+        printf("#define NVRAM_OTP_TOTAL   %d\n" % global_value.otp_total_to_verify, file=fd, end="")
+    printf("#define NVRAM_CUSTPACK_TOTAL  %d\n" % global_value.custpack_total_to_verify, file=fd, end="")
+
+    printf("#define NVRAM_SECUPACK_SIZE  %d\n" % global_value.secupack_size_to_verify, file=fd, end="")
+    printf("#define NVRAM_SECUPACK_TOTAL  %d\n" % global_value.secupack_total_to_verify, file=fd, end="")
+    if global_value.macro & const_value.__NVRAM_SECURE_DATA_STORAGE__:  # __NVRAM_SECURE_DATA_STORAGE__
+        printf("#define NVRAM_SDS_TOTAL    %d\n" % global_value.sds_total_to_verify, file=fd, end="")
+        printf("#define NVRAM_SDS_SIZE   %d\n" % global_value.sds_size_to_verify, file=fd, end="")
+    if global_value.macro & const_value.__NVRAM_PSEUDO_MERGE__:  # __NVRAM_PSEUDO_MERGE__
+        printf("\n", file=fd, end="")
+        printf("#ifdef __NVRAM_PSEUDO_MERGE__\n", file=fd, end="")
+        printf("#define NVRAM_PACKAGE_LID_NUM     %d\n" % global_value.nvram_auto_package_num, file=fd, end="")
+        printf("#define NVRAM_PACKAGE_LID_SIZE    %d\n" % global_value.nvram_auto_pack_file_offset, file=fd, end="")
+        printf("#endif /* __NVRAM_PSEUDO_MERGE__ */\n", file=fd, end="")
+
+    printf("\n#endif /* NVRAM_LID_STATISTIC_H */\n\n", file=fd, end="")
+    fd.close()
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/initconfig.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/initconfig.py
new file mode 100644
index 0000000..975bfec
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/initconfig.py
@@ -0,0 +1,580 @@
+import logging
+import os
+import re
+import sys
+
+
+nvram_algo_type = {1: "NVRAM_MD5", 2: "NVRAM_HMAC_SHA256"}
+nvram_algo_type_str = {"NVRAM_MD5": 1, "NVRAM_HMAC_SHA256": 2}
+
+def nvram_is_category_in_bin_region(x):
+    return ((x) & (const_value.NVRAM_CATEGORY_CALIBRAT | const_value.NVRAM_CATEGORY_IMPORTANT))
+def nvram_is_category_factory_reset(x):
+    return (not ((x) & (const_value.NVRAM_CATEGORY_IMPORTANT_L1 | const_value.NVRAM_CATEGORY_IMPORTANT_L4)))
+
+def get_checksum_size(ldi):
+    ret = const_value.NVRAM_CHKSUM_SIZE
+    if global_value.macro & const_value.__NV_CHKSUM_ENHANCE__:
+        if ldi.attr & const_value.NVRAM_ATTR_CHKSM_ENHNC_ALGRTHM:
+            if global_value.enhance_type  == nvram_algo_type_str["NVRAM_MD5"]:
+                ret = const_value.NVRAM_CHKSUM_SIZE
+            else:
+                ret = global_value.enhance_size
+        else:
+            if global_value.default_type  == nvram_algo_type_str["NVRAM_MD5"]:
+                ret = const_value.NVRAM_CHKSUM_SIZE
+            else:
+                ret = global_value.default_size
+    
+    return ret
+
+def autogen_open_file(file_path, file_name, mode="r"):
+    file_pathname = os.path.join(file_path, file_name)
+    try:
+        fd = open(file_pathname, mode)
+    except:
+        printf("error: open file error.")
+        printf("file_pathname: %s , mode: %s" % (file_pathname, mode))
+        global_value.logger.error("open file error.")
+        global_value.logger.error("file_pathname: %s , mode: %s", file_pathname, mode)
+        raise
+    
+    return fd
+
+def printf(strs, file=sys.stdout, end="\n", flush=False):
+    strs_val = strs + end
+    file.write(strs_val)
+    if flush:
+        file.flush()
+
+# LID table class =======================================
+class LtableEntry(object):
+    lid = 0
+    total_records = 0
+    size = 0
+    p_str_default_value = 0x00
+    str_default_value = ""
+    p_default_value = 0x00
+    default_value = []
+    default_value_len = 0
+    category = 0
+    attr = 0
+    FilePrefix = ""
+    FileVerno = ""
+    p_str_LID = 0x00
+    str_LID = ""
+    p_description = 0x00
+    description = "null"
+    hash_key = 0
+    FileSize = 0
+    FullPath = ""
+
+    
+# def NVRAM_LID_GRP_INTERNAL(x):
+def nvram_lid_grp_internal(x):
+    return (0xF000 | (0x00FF & x))
+
+# def NVRAM_LID_GRP_CORE(x):
+def nvram_lid_grp_core(x):
+    return (0xF200 | (0x00FF & x))
+
+# const value class =======================================
+class ConstValue(object):
+
+    def __init__(self):
+        # nvram_attr_enum
+        self.NVRAM_ATTR_AVERAGE = 0x00000000
+        self.NVRAM_ATTR_MULTI_DEFAULT = 0x00000001
+        self.NVRAM_ATTR_WRITEPROTECT = 0x00000002
+        self.NVRAM_ATTR_MULTIPLE = 0x00000004
+        self.NVRAM_ATTR_CONFIDENTIAL = 0x00000008
+        self.NVRAM_ATTR_MULTIREC_READ = 0x00000010
+        self.NVRAM_ATTR_MSP = 0x00000020
+        self.NVRAM_ATTR_OTA_RESET = 0x00000040
+        self.NVRAM_ATTR_GEN_DEFAULT = 0x00000080
+        self.NVRAM_ATTR_RING = 0x00000100
+        self.NVRAM_ATTR_PACKAGE = 0x00000200
+        self.NVRAM_ATTR_BACKUP_FAT = 0x00000400
+        self.NVRAM_ATTR_BACKUP_RAW = 0x00000800
+        self.NVRAM_ATTR_RESERVE_BACKWARD = 0x00001000
+        self.NVRAM_ATTR_FAULT_ASSERT = 0x00002000
+        self.NVRAM_ATTR_COMMITTED = 0x00004000
+        self.NVRAM_ATTR_RAW_DATA = 0x00008000
+        self.NVRAM_ATTR_CHKSUM_INTEGRATE = 0x00010000
+        self.NVRAM_ATTR_CHKSM_ENHNC_ALGRTHM = 0x00020000
+        self.NVRAM_ATTR_MCF_OTA_ADDITIONAL_NOT_CHECK_VERNO = 0x10000000
+        self.NVRAM_ATTR_MCF_OTA_FOR_QUERY = 0x20000000
+        self.NVRAM_ATTR_MCF_OTA_BY_OP = 0x40000000
+        self.NVRAM_ATTR_MCF_OTA = 0x80000000
+        self.NVRAM_ATTR_ALL = 0xFFFFFFFF
+
+        # nvram_category_enum
+        self.NVRAM_CATEGORY_USER = 0x0000
+        self.NVRAM_CATEGORY_INTERNAL = 0x0001
+        self.NVRAM_CATEGORY_BACKUP_SDS = 0x0010
+        self.NVRAM_CATEGORY_OTP = 0x0020
+        self.NVRAM_CATEGORY_CUSTOM_DISK = 0x0040
+        self.NVRAM_CATEGORY_CUSTOM_SENSITIVE = 0x0080
+        self.NVRAM_CATEGORY_CUSTPACK = 0x0100
+        self.NVRAM_CATEGORY_SECUPACK = 0x0200
+        self.NVRAM_CATEGORY_FUNC_DEFAULT = 0x0400
+        self.NVRAM_CATEGORY_CALIBRAT = 0x1000
+        self.NVRAM_CATEGORY_IMPORTANT = 0x2000
+        self.NVRAM_CATEGORY_IMPORTANT_L4 = 0x4000
+        self.NVRAM_CATEGORY_IMPORTANT_L1 = 0x8000
+        self.NVRAM_CATEGORY_ALL = 0xFFFF
+        self.NVRAM_CATEGORY_RESERVED = 0x80000000
+
+        self.NVRAM_CHKSUM_SIZE = 8
+        self.NVRAM_CHECKSUM_SIZE = 2
+        self.NVRAM_CLUSTER_SIZE = 900
+        self.NVRAM_RECORD_SECTOR_SIZE = 512
+        self.NVRAM_MSP_ALIGNMENT = 16
+        # share memery padding
+        self.SHARE_MEM_64BYTE_ALIGN = 64
+        self.DIRTY_BLOCK_SIZE = 32
+        self.DIRTY_4BYTE_ALIGN = 4
+        self.FS_PAGE_SIZE = 4096
+        self.NVRAM_LDI_OTA_HEADER_SIZE = 32
+        self.NVRAM_LDI_DEBUG_HEADER_SIZE = 32
+        self.NVRAM_LDI_APPENDIX_HEADER_SIZE = 32
+        self.NVRAM_LDI_HEADER_SIZE = self.NVRAM_LDI_OTA_HEADER_SIZE + self.NVRAM_LDI_DEBUG_HEADER_SIZE
+        self.RAM_FS_SIZE = 0x01000000
+        # cache size
+        self.SHARE_MEMORY_SIZE = 0x1200000
+
+        # core folder
+        self.NVRAM_FS_DATAITEM_PATH = "Z:\\\\NVRAM\\\\NVD_DATA"
+        self.NVRAM_FS_COREITEM_PATH = "Z:\\\\NVRAM\\\\NVD_CORE"
+        self.NVRAM_FS_CALIBRAT_DATAITEM_PATH = "Z:\\\\NVRAM\\\\CALIBRAT"
+        self.NVRAM_FS_IMPT_DATAITEM_PATH = "Z:\\\\NVRAM\\\\NVD_IMEI"
+        self.NVRAM_FS_IMPORTNT_DATAITEM_PATH = "Z:\\\\NVRAM\\\\IMPORTNT"
+        self.NVRAM_FS_CUST_DATAITEM_PATH = "Z:\\\\NVRAM\\\\NVD_CUST"
+        self.NVRAM_FS_BACKUP_ROOT_PATH = "G:\\\\NVRAM"
+
+        self.NVRAM_TEST_FS_DATAITEM_PATH = "Z:\\\\NV_TEST\\\\NVD_DATA"
+        self.NVRAM_TEST_FS_COREITEM_PATH = "Z:\\\\NV_TEST\\\\NVD_CORE"
+        self.NVRAM_TEST_FS_CALIBRAT_DATAITEM_PATH = "Z:\\\\NV_TEST\\\\CALIBRAT"
+        self.NVRAM_TEST_FS_IMPT_DATAITEM_PATH = "Z:\\\\NV_TEST\\\\NVD_IMEI"
+        self.NVRAM_TEST_FS_CUST_DATAITEM_PATH = "Z:\\\\NV_TEST\\\\NVD_CUST"
+        self.NVRAM_TEST_FS_IMPORTNT_DATAITEM_PATH = "Z:\\\\NV_TEST\\\\IMPORTNT"
+
+        # sys cache enum
+        self.NVRAM_SYS_CACHE_BEGIN = 1
+        self.NVRAM_SYS_CACHE_MAX = 18
+        self.NVRAM_APP_TOTAL = 1
+
+        # custom key
+        self.NVRAM_SECRET_KEY_SIZE = 8
+        self.NVRAM_CUSTOM_KEY_SEED_SIZE = 32
+        self.NVRAM_AUTO_GEN_BYTE = 1
+        self.NVRAM_AUTO_GEN_SHORT = 2
+        self.NVRAM_AUTO_GEN_INTEGER = 4
+
+        # macro
+        self.__CCCIFS_SUPPORT__ = 1 << 0
+        self.__NVRAM_LID_CACHE__ = 1 << 1
+        self.__NVRAM_LID_HASH_CHECK__ = 1 << 2
+        self.__MTK_INTERNAL__ = 1 << 3
+        self.__NVRAM_UT_TEST__ = 1 << 4
+        self.__NVRAM_BACKUP_DISK_FAT__ = 1 << 5
+        self.__NVRAM_BACKUP_DISK_RAW__ = 1 << 6
+        self.__LOW_COST_SUPPORT_COMMON__ = 1 << 7
+        self.__FS_RAMDISK__ = 1 << 8
+        self.__NVRAM_OTP__ = 1 << 9
+        self.__NVRAM_PSEUDO_MERGE__ = 1 << 10
+        self.__NVRAM_CUSTOM_SENSITIVE__ = 1 << 11
+        self.__NVRAM_CUSTOM_DISK__ = 1 << 12
+        self.__NVRAM_BIND_TO_CHIP_CIPHER__ = 1 << 13
+        self._SIMULATION = 1 << 14
+        self.__PALLADIUM__ = 1 << 15
+        self.__FPGA__ = 1 << 16
+        self.__NVRAM_SECURE_DATA_STORAGE__ = 1 << 17
+        self.__NVRAM_LARGE_RECORD_SIZE__ = 1 << 18
+        self.__NVRAM_VENDOR_SUPPORT__ = 1 << 19
+        self.__VENDOR_RELEASE__ = 1 << 20
+        self.__L1_STANDALONE__ = 1 << 21
+        self.__MMI_FMI__ = 1 << 22
+        self.__NVRAM_COMPRESS_SUPPORT__ = 1 << 23
+        self.__MTK_TARGET__ = 1 << 24
+        self.__NVRAM_IMPORTANT_PARTIONS__ = 1 << 25
+        self.__NV_CHKSUM_ENHANCE__ = 1 << 26
+        self.__NVRAM_PARTIAL_CACHE__ = 1 << 27
+
+        # 
+        self.NVRAM_EF_NVRAM_UNIT_TEST_LID = nvram_lid_grp_internal(16)      #  NVRAM_LID_GRP_INTERNAL(x)
+        self.NVRAM_EF_NVRAM_UNIT_TEST_LID_END = nvram_lid_grp_internal(34)  #  NVRAM_LID_GRP_CORE(x)
+        self.NVRAM_EF_START = nvram_lid_grp_core(0) # 
+        
+        # check target 64bit or 32bit 
+        self.WIN_BIT_ADDR = 0x84
+        self.WIN_32BIT_DATA = 0x4c
+        self.WIN_64BIT_DATA = 0x64
+        
+        self.LINUX_BIT_ADDR = 0x4
+        self.LINUX_32BIT_DATA = 0x01
+        self.LINUX_64BIT_DATA = 0x02
+        
+        self.TARGET_32BIT = 0x01
+        self.TARGET_64BIT = 0X02
+        
+        
+
+    class ConstError(TypeError):
+        pass
+
+    class ConstCaseError(ConstError):
+        pass
+
+    def __setattr__(self, key, value):
+        if key in self.__dict__.keys():
+            if key is not "SHARE_MEMORY_SIZE":
+                raise self.ConstError("Can't change a const variable: '%s'" % key)
+        if not key.isupper():
+            raise self.ConstCaseError("Const variable must be combined with upper letters:'%s'" % key)
+        # add value
+        self.__dict__[key] = value
+
+    @property
+    def SIMULATION(self):
+        return self._SIMULATION
+
+
+class GlobalValue(object):
+    path = "."
+    logging_path = "."
+    autogen_path = "."
+    log_path = "."
+    const = ConstValue()
+    # logger = logging.getLogger("nvram_auto")
+    logger = logging
+    
+    table_offset = 0x0
+    table_len = 0x0
+    nvram_ltable_entry_length = 0x0
+    platform = ""
+    
+    # .map addr & off (Linux)
+    rodata_lma = 0x0
+    rodata_off = 0x0
+    data_lma = 0x0
+    data_off = 0x0
+    bss_lma = 0x0
+    bss_off = 0x0
+    
+    # .map addr (win)
+    text_addr = 0x0
+    text_len = 0x0
+    data_addr = 0x0
+    data_len = 0x0
+    bss_addr = 0x0
+    bss_len = 0x0
+    image_base = 0x0
+    text_offset = 0x0
+    data_offset = 0x0
+    bss_offset = 0x0
+    ltable_offset = 0x0
+
+    # macro define
+    macro = 0x0
+
+    # information.log
+    nvram_long_length = 0
+    nvram_ptr_length = 0
+    nvram_padding_length = 0
+
+    # statistic lid table
+    otp_size_to_verify = 0
+    otp_total_to_verify = 0
+    custpack_total_to_verify = 0
+    secupack_size_to_verify = 0
+    secupack_total_to_verify = 0
+    sds_total_to_verify = 0
+    sds_size_to_verify = 0
+    nvram_auto_package_num = 0
+    nvram_auto_pack_file_offset = 0
+    
+    # 
+    target_bit = 0x0  # target 32bit or 64bit
+    
+    # enhance algo
+    default_type = 0x00
+    default_size = 0x00
+    enhance_type = 0x00
+    enhance_size = 0x00
+
+    def logger_config(self, outLevel=logging.DEBUG):
+        # create formatter and add it to the handlers
+        formatter = logging.Formatter('%(levelname)-10s : %(message)s')
+        info_log_path = os.path.join(self.log_path, "nvram_gen_full_log.log")
+        self.logger.basicConfig(filename=info_log_path, filemode="a",
+                format='%(levelname)-8s : %(message)s', level=logging.INFO)
+            
+        # add handler for error log
+        err_log_path = os.path.join(self.log_path, "nvram_gen.log")
+        error_handler = logging.FileHandler(err_log_path, mode="a")
+        err_format = logging.Formatter("%(levelname)-6s: [autogen]: %(message)s")
+        error_handler.setFormatter(err_format)
+        error_handler.setLevel(logging.ERROR)
+        self.logger.getLogger("").addHandler(error_handler)
+
+    def pars_macro_info(self):
+        """ parse of macro from info.log """
+        self.logger.info("===== pars_macro_info begin =====")
+        # fd = open(os.path.join(self.path, "bin", "log", "info.log"), "r")
+        fd = autogen_open_file(self.log_path, "info.log", "r")
+        macro_option = 0x0
+        __SYSDRV_BACKUP_DISK__ = 1 << 0
+        __SYSDRV_BACKUP_DISK_FAT__ = 1 << 1
+        __SYSDRV_BACKUP_DISK_RAW__ = 1 << 2
+        __TC01__ = 1 << 3
+        __NVRAM_MULTI_FOLDERS__ = 1 << 4
+        __CUSTOMER_TC01_DISK__ = 1 << 5
+        __MTK_TARGET__ = 1 << 6
+        __SECURE_DATA_STORAGE__ = 1 << 7
+        __LTE_RAT__ = 1 << 8
+        __C2K_RAT__ = 1 << 9
+        __MA_L1__ = 1 << 10
+        __UMTS_RAT__ = 1 << 11
+        __DHL_MODULE__ = 1 << 12
+        NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM = 1 << 13
+
+        for each_line in fd:
+            if each_line.isspace():  # It's all blank
+                continue
+            if re.search("\[ COMMON INCLUDE PATH \]", each_line):
+                break
+            if re.search("\[ COMMON OPTION \]", each_line):
+                continue
+            # if each_line.count("[ COMMON INCLUDE PATH ]") != 0:
+            #     break
+            # if (each_line.count("[") != 0) or (each_line.count("]") != 0):
+            #     continue
+            strs = each_line.rstrip()  # clear tail character ('\n' ' ' '\t' '\r')
+            if strs == "__CCCIFS_SUPPORT__":
+                self.macro |= const_value.__CCCIFS_SUPPORT__
+                continue
+            if strs == "__NVRAM_LID_CACHE__":
+                self.macro |= const_value.__NVRAM_LID_CACHE__
+                continue
+            if strs == "__NVRAM_PARTIAL_CACHE__":
+                self.macro |= const_value.__NVRAM_PARTIAL_CACHE__
+                const_value.SHARE_MEMORY_SIZE = 0x700000
+                continue
+            if strs == "__NVRAM_LID_HASH_CHECK__":
+                self.macro |= const_value.__NVRAM_LID_HASH_CHECK__
+                continue
+            if strs == "__MTK_INTERNAL__":
+                self.macro |= const_value.__MTK_INTERNAL__
+                continue
+            if strs == "__NVRAM_UT_TEST__":
+                self.macro |= const_value.__NVRAM_UT_TEST__
+                continue
+            if strs == "__NVRAM_BACKUP_DISK_FAT__":
+                self.macro |= const_value.__NVRAM_BACKUP_DISK_FAT__
+                continue
+            if strs == "__NVRAM_BACKUP_DISK_RAW__":
+                self.macro |= const_value.__NVRAM_BACKUP_DISK_RAW__
+                continue
+            if strs == "__LOW_COST_SUPPORT_COMMON__":
+                self.macro |= const_value.__LOW_COST_SUPPORT_COMMON__
+                continue
+            if strs == "__FS_RAMDISK__":
+                self.macro |= const_value.__FS_RAMDISK__
+                continue
+            if strs == "__NVRAM_OTP__":
+                self.macro |= const_value.__NVRAM_OTP__
+                continue
+            if strs == "__NVRAM_PSEUDO_MERGE__":
+                self.macro |= const_value.__NVRAM_PSEUDO_MERGE__
+                continue
+            if strs == "__NVRAM_CUSTOM_SENSITIVE__":
+                self.macro |= const_value.__NVRAM_CUSTOM_SENSITIVE__
+                continue
+            if strs == "__NVRAM_CUSTOM_DISK__":
+                self.macro |= const_value.__NVRAM_CUSTOM_DISK__
+                continue
+            if strs == "__NVRAM_BIND_TO_CHIP_CIPHER__":
+                self.macro |= const_value.__NVRAM_BIND_TO_CHIP_CIPHER__
+                continue
+            if strs == "_SIMULATION":
+                self.macro |= const_value._SIMULATION
+                continue
+            if strs == "__PALLADIUM__":
+                self.macro |= const_value.__PALLADIUM__
+                continue
+            if strs == "__FPGA__":
+                self.macro |= const_value.__FPGA__
+                continue
+            if strs == "__NVRAM_SECURE_DATA_STORAGE__":
+                self.macro |= const_value.__NVRAM_SECURE_DATA_STORAGE__
+                continue
+            if strs == "__NVRAM_LARGE_RECORD_SIZE__":
+                self.macro |= const_value.__NVRAM_LARGE_RECORD_SIZE__
+                continue
+            if strs == "__NVRAM_VENDOR_SUPPORT__":
+                self.macro |= const_value.__NVRAM_VENDOR_SUPPORT__
+                continue
+            if strs == "__VENDOR_RELEASE__":
+                self.macro |= const_value.__VENDOR_RELEASE__
+                continue
+            if strs == "__L1_STANDALONE__":
+                self.macro |= const_value.__L1_STANDALONE__
+                continue
+            if strs == "__MMI_FMI__":
+                self.macro |= const_value.__MMI_FMI__
+                continue
+            if strs == "__NVRAM_COMPRESS_SUPPORT__":
+                self.macro |= const_value.__NVRAM_COMPRESS_SUPPORT__
+                continue
+            if strs == "__NVRAM_IMPORTANT_PARTIONS__":
+                self.macro |= const_value.__NVRAM_IMPORTANT_PARTIONS__
+                continue
+            if strs == "__NV_CHKSUM_ENHANCE__":
+                self.macro |= const_value.__NV_CHKSUM_ENHANCE__
+                continue
+            if strs == "__SYSDRV_BACKUP_DISK__":
+                macro_option |= __SYSDRV_BACKUP_DISK__
+                continue
+            if strs == "__SYSDRV_BACKUP_DISK_FAT__":
+                macro_option |= __SYSDRV_BACKUP_DISK_FAT__
+                continue
+            if strs == "__SYSDRV_BACKUP_DISK_RAW__":
+                macro_option |= __SYSDRV_BACKUP_DISK_RAW__
+                continue
+            if strs == "__TC01__":
+                macro_option |= __TC01__
+                self.macro |= const_value.__NVRAM_LARGE_RECORD_SIZE__
+                continue
+            if strs == "__NVRAM_MULTI_FOLDERS__":
+                macro_option |= __NVRAM_MULTI_FOLDERS__
+                continue
+            if strs == "__CUSTOMER_TC01_DISK__":
+                macro_option |= __CUSTOMER_TC01_DISK__
+                continue
+            if strs == "__MTK_TARGET__":
+                macro_option |= __MTK_TARGET__
+                self.macro |= const_value.__MTK_TARGET__
+                continue
+            if strs == "__SECURE_DATA_STORAGE__":
+                macro_option |= __SECURE_DATA_STORAGE__
+                continue
+            if strs == "__LTE_RAT__":
+                macro_option |= __LTE_RAT__
+                continue
+            if strs == "__C2K_RAT__":
+                macro_option |= __C2K_RAT__
+                continue
+            if strs == "__MA_L1__":
+                macro_option |= __MA_L1__
+                continue
+            if strs == "__UMTS_RAT__":
+                macro_option |= __UMTS_RAT__
+                continue
+            if strs == "__DHL_MODULE__":
+                macro_option |= __DHL_MODULE__
+                continue
+            """if strs.find("NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM") != -1:
+                macro_option |= NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM
+                list_temp = re.split("=", strs)
+                const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM = int(list_temp[1])
+                const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SIZE = const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM * const_value.NVRAM_RECORD_SECTOR_SIZE
+            """
+        if macro_option & __SYSDRV_BACKUP_DISK__:
+            if macro_option & __SYSDRV_BACKUP_DISK_FAT__:
+                self.macro |= const_value.__NVRAM_BACKUP_DISK_FAT__
+            if macro_option & __SYSDRV_BACKUP_DISK_RAW__:
+                self.macro |= const_value.__NVRAM_BACKUP_DISK_RAW__
+        if not (self.macro & const_value.__NVRAM_PSEUDO_MERGE__):
+            macro_option |= __NVRAM_MULTI_FOLDERS__
+                
+        if (macro_option & __TC01__) and (macro_option & __NVRAM_MULTI_FOLDERS__):
+            self.macro |= const_value.__NVRAM_CUSTOM_SENSITIVE__
+        if (macro_option & __CUSTOMER_TC01_DISK__) and (self.macro & const_value.__MTK_TARGET__):
+            self.macro |= const_value.__NVRAM_CUSTOM_DISK__
+        if macro_option & __SECURE_DATA_STORAGE__:
+            self.macro |= const_value.__NVRAM_SECURE_DATA_STORAGE__
+        """if not self.macro & const_value.__NVRAM_SECURE_DATA_STORAGE__:
+            if macro_option & __SECURE_DATA_STORAGE__:
+                self.macro |= const_value.NVRAM_ATTR_BACKUP_FAT
+        """
+        if not macro_option & NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM:
+            if macro_option & __LTE_RAT__:
+                const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM = 128
+            elif (macro_option & __C2K_RAT__) and not(macro_option & __LTE_RAT__):
+                const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM = 128
+            elif macro_option & (__MA_L1__ | __UMTS_RAT__):
+                const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM = 16
+            elif macro_option & __DHL_MODULE__:
+                const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM = 8
+            else:
+                const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM = 4
+            const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SIZE = const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM * const_value.NVRAM_RECORD_SECTOR_SIZE
+        self.logger.info("macro = 0x%x", self.macro)
+        self.logger.info("===== pars_macro_info end =====")
+
+
+logical_data_item_table = []
+const_value = ConstValue()
+global_value = GlobalValue()
+
+COPYRIGHTS_HEADER = """/*****************************************************************************
+*  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:
+ *   %s
+ *
+ * Project:
+ *   MAUI
+ *
+ * Description:
+ *   This file is intends for NVRAM auto gen statistics
+ *
+ * Author:
+ *   nvram auto gen !
+ * -------
+ *
+ *============================================================================
+ *
+ * This file is automatically generated by the nvram gen procedure
+ *
+ ****************************************************************************/
+"""
+
+if __name__ == '__main__':
+    pass
+    # const = ConstValue()
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/mcf_ota_helper.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/mcf_ota_helper.py
new file mode 100644
index 0000000..7151997
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/mcf_ota_helper.py
@@ -0,0 +1,82 @@
+import os
+import platform
+import re
+
+from .initconfig import global_value
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import COPYRIGHTS_HEADER
+from .initconfig import printf
+from .initconfig import autogen_open_file
+
+
+def nvram_gen_ltable_list():
+    
+    map_file = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.map", "r")
+    tbl_list = autogen_open_file(global_value.autogen_path, "nvram_ltable_list.h", "w+")
+    
+    indirect_process_yet = 0
+    indirect_process_ing = 1
+    indirect_process_finished = 2
+    process_indirect_init = indirect_process_yet
+    
+    if global_value.platform == "Windows":  # windows
+        indirect_end_symbol = "_indirect_init_end = ."
+    else:
+        indirect_end_symbol = "indirect_init_end = ."
+    
+    
+
+    line = map_file.readline()
+    while line:
+        if process_indirect_init == indirect_process_yet:
+            if line.find("logical_data_item_table_") != -1:
+                str = re.search("logical_data_item_table_\w*", line).group()
+                printf("#pragma comment(linker, \"/INCLUDE:_%s\")\n" % str, file=tbl_list, end="")
+            if line.find("*(_indirect_init)") != -1:
+                process_indirect_init = indirect_process_ing
+                line = map_file.readline()
+                if line.find(indirect_end_symbol) != -1:
+                    process_indirect_init = indirect_process_finished
+                    break
+        elif process_indirect_init == indirect_process_ing:
+            if line.find(indirect_end_symbol) != -1:
+                process_indirect_init = indirect_process_finished
+                break
+            ptr = line[line.find(" ") + 1:]
+            if line.find("./build/") == -1:
+                printf("#pragma comment(linker, \"/INCLUDE:_%s\")\n" % ptr, file=tbl_list, end="")
+        line = map_file.readline()
+
+    map_file.close()
+    tbl_list.close()
+
+
+def nvram_gen_mcf_ota_lid_list():
+    
+    fd = autogen_open_file(global_value.autogen_path, "nvram_lid_list_for_mcf.h", "w+")
+
+    printf(COPYRIGHTS_HEADER % "nvram_lid_list_for_mcf.h", file=fd, end="")
+    printf("#ifndef __NVRAM_LID_LIST_FOR_MCF__\n", file=fd, end="")
+    printf("#define __NVRAM_LID_LIST_FOR_MCF__\n", file=fd, end="")
+    printf("#include \"kal_general_types.h\"\n", file=fd, end="")
+    printf("typedef enum\n{\n", file=fd, end="")
+    for ldi in logical_data_item_table:
+        if ldi.lid == 0 or ldi.size == 0 or ldi.total_records == 0:
+            continue
+        if ldi.attr & const_value.NVRAM_ATTR_MCF_OTA or ldi.attr & const_value.NVRAM_ATTR_MCF_OTA_FOR_QUERY:
+            printf("    %s,    \n" % ldi.str_LID, file=fd, end="")
+
+    printf("    NVRAM_EF_LAST_%s\n}%s;\n\n" %("LID", "nvram_mcf_ota_lid"), file=fd, end="")
+
+    printf("typedef enum\n{\n", file=fd, end="")
+
+    for ldi in logical_data_item_table:
+        if ldi.lid == 0 or ldi.size == 0 or ldi.total_records == 0:
+            continue
+        if ldi.attr & const_value.NVRAM_ATTR_MCF_OTA_BY_OP:
+            printf("    %s,    \n" % ldi.str_LID, file=fd, end="")
+    printf("    NVRAM_EF_LAST_%s\n}%s;\n\n" % ("LID", "nvram_mcf_ota_by_operator_lid"), file=fd, end="")
+    printf("#endif\n", file=fd, end="")
+    fd.close()
+
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/secupackhelper.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/secupackhelper.py
new file mode 100644
index 0000000..19862ff
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/secupackhelper.py
@@ -0,0 +1,208 @@
+import os
+import re
+import struct
+import sys
+
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import global_value
+from .initconfig import COPYRIGHTS_HEADER
+from .initconfig import printf, nvram_algo_type
+from .initconfig import autogen_open_file
+from .tableconstructor import offset_elf
+
+
+def parse_custom_key(fd_target):
+    """ parse key data in .map&.exe"""
+    fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.map", "r")
+    # -----------------------------
+    # parse offset in target.map
+    for each_line in fd:
+       
+        if re.search("custom_secret_key", each_line):
+            s = each_line.strip()
+            list_secret = s.split()
+            secret_key_offset = int(list_secret[0], base=16)
+            continue
+        
+        if re.search("custom_key_seed", each_line):
+            s = each_line.strip()
+            list_seed = s.split()
+            key_seed_offset = int(list_seed[0], base=16)
+            continue
+    fd.close()
+    # ===
+    global_value.logger.info("secret_key_offset = 0x%x, key_seed_offset = 0x%x", secret_key_offset, key_seed_offset)  
+    if not secret_key_offset:
+        global_value.logger.error("secret_key_offset = 0 ,read secret_key_offset error!")  
+        sys.exit(1)
+    if not key_seed_offset:
+        global_value.logger.error("key_seed_offset = 0 ,read key_seed_offset error!")  
+        sys.exit(1)
+    # ===
+    
+    
+    # -------------------------------
+    # calculate offset
+    secret_key_offset = offset_elf(secret_key_offset)
+    key_seed_offset = offset_elf(key_seed_offset)
+    
+    
+    # -------------------------------
+    # parse key data
+    
+    fd_target.seek(secret_key_offset)
+    r_bin = fd_target.read(const_value.NVRAM_SECRET_KEY_SIZE)
+    s = struct.unpack('8B', r_bin)
+    secret_key_list = list(s)
+
+    fd_target.seek(key_seed_offset)
+    r_bin = fd_target.read(const_value.NVRAM_CUSTOM_KEY_SEED_SIZE)
+    s = struct.unpack('32B', r_bin)
+    key_seed_list = list(s)
+
+    # fd.close()
+
+    return secret_key_list, key_seed_list
+    
+    
+
+
+def write_secro_tbl(fd):
+    """ output secupack lid to custom_nvram_secro_tbl.c"""
+    printf("#if defined(NVRAM_SEC_C_ONLY)\n", file=fd, end="")
+    printf("const nvram_lid_enum secupack_nvram_lid_tbl[%d] = \n" % global_value.secupack_total_to_verify, file=fd,
+          end="")
+    printf("{", file=fd, end="")
+
+    for ldi in logical_data_item_table:
+        if ldi.category & const_value.NVRAM_CATEGORY_SECUPACK:
+            printf("\n   %d," % ldi.lid, file=fd, end="")
+    printf("\n};", file=fd, end="")
+    printf("\n#endif", file=fd, end="")
+
+
+def nvram_gen_array(fd, indent, type, max_size, list, calc_cksum, last_block):
+    """ outpur formatted arrays to custom_nvram_secro
+        args:
+            calc_cksum: true add check sum/ false not add check sum
+    """
+    i = 0
+    byte_chksum = [0, 0]
+    while i < max_size:
+        if calc_cksum and type == const_value.NVRAM_AUTO_GEN_BYTE:
+            if i & 0x1:
+                byte_chksum[1] += list[i]
+            else:
+                byte_chksum[0] += list[i]
+
+        if i % 16 == 0:
+            printf("\n%s" % indent, file=fd, end="")
+
+        if type == const_value.NVRAM_AUTO_GEN_INTEGER:
+            printf("0x%02X%02X%02X%02X" % (list[i + 3], list[i + 2], list[i + 1], list[i]), file=fd, end="")
+        elif type == const_value.NVRAM_AUTO_GEN_SHORT:
+            printf("0x%02X%02X" % (list[i + 1], list[i]), file=fd, end="")
+        else:
+            printf("0x%02X" % list[i], file=fd, end="")
+
+        if i == max_size - type:
+            if calc_cksum and type == const_value.NVRAM_AUTO_GEN_BYTE:
+                printf(",\n%s/* check sum */\n%s0x%02x, 0x%02x" % (
+                indent, indent, byte_chksum[0] & 0xff, byte_chksum[1] & 0xff), file=fd, end="")
+
+            if not last_block:
+                printf(", ", file=fd, end="")
+        else:
+            printf(", ", file=fd, end="")
+        i += type
+
+
+def nvram_gen_secro():
+    """ gen file: custom_nvram_secro.c / custom_nvram_secro_tbl.c"""
+    fd_1 = autogen_open_file(global_value.autogen_path, "custom_nvram_secro.c", "w+")
+    fd_2 = autogen_open_file(global_value.autogen_path, "custom_nvram_secro_tbl.c", "w+")
+    
+    write_secro_tbl(fd_2)
+    fd_2.close()
+    
+    if global_value.platform == "Windows":
+        fd_target = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.exe", "rb")
+        
+    else:
+        fd_target = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target", "rb")
+        
+    
+    custom_secret_key, custom_key_seed = parse_custom_key(fd_target)
+    fd_target.close()
+
+    printf(COPYRIGHTS_HEADER % "custom_nvram_secro.c", file=fd_1, end="")
+
+    printf("#if !defined(NVRAM_NOT_PRESENT)\n", file=fd_1, end="")
+    printf("#include \"kal_general_types.h\"\n", file=fd_1, end="") 
+    printf("#include \"custom_nvram_sec.h\"\n", file=fd_1, end="")    
+    
+
+    # write custom secret key
+    printf("const kal_uint8 NVRAM_CUSTOM_KEY[] = \n", file=fd_1, end="")
+    printf("    {", file=fd_1, end="")
+    nvram_gen_array(fd_1, "        ", const_value.NVRAM_AUTO_GEN_BYTE, const_value.NVRAM_SECRET_KEY_SIZE,
+                    custom_secret_key, False, True)
+    printf("\n    };\n", file=fd_1, end="")
+
+    # write custom key seed
+    printf("const kal_uint8 NVRAM_CUSTOM_KEY_SEED[] = \n", file=fd_1, end="")
+    printf("    {", file=fd_1, end="")
+    nvram_gen_array(fd_1, "        ", const_value.NVRAM_AUTO_GEN_BYTE, const_value.NVRAM_CUSTOM_KEY_SEED_SIZE,
+                    custom_key_seed, False, True)
+    printf("\n    };\n", file=fd_1, end="")
+
+    printf("#if defined(__RES_PROT__)\n", file=fd_1, end="")
+    printf("__attribute__((section(\"PROTECTED_RES_RW\")))\n", file=fd_1, end="")
+    printf("#endif\n", file=fd_1, end="")
+
+    printf("const kal_uint8 NVRAM_SECUPACK_DEFAULT[] = \n", file=fd_1, end="")
+    printf("    {", file=fd_1, end="")
+    secupack_idx = 0
+    for ldi in logical_data_item_table:
+        if ldi.category & const_value.NVRAM_CATEGORY_SECUPACK:
+            if secupack_idx != 0:
+                printf("\n", file=fd_1, end="")
+            printf("\n        /* %s */" % ldi.str_LID, file=fd_1, end="")
+            if secupack_idx + 1 == global_value.secupack_total_to_verify:
+                nvram_gen_array(fd_1, "        ", const_value.NVRAM_AUTO_GEN_BYTE, ldi.default_value_len,
+                                ldi.default_value, True, True)
+            else:
+                nvram_gen_array(fd_1, "        ", const_value.NVRAM_AUTO_GEN_BYTE, ldi.default_value_len,
+                                ldi.default_value, True, False)
+            secupack_idx += 1
+
+    if global_value.secupack_total_to_verify == 0:
+        printf("\n        0x00, 0x00", file=fd_1, end="")
+    printf("\n    };", file=fd_1, end="")
+
+    printf("\nkal_uint32 secupack_total_to_verify = %d;" % global_value.secupack_total_to_verify, file=fd_1, end="")
+    printf("\n#endif /* NVRAM_NOT_PRESENT */", file=fd_1, end="")
+
+    fd_1.close()
+    
+    # write custom algo config
+    if global_value.macro & const_value.__NV_CHKSUM_ENHANCE__:
+        fd = autogen_open_file(global_value.autogen_path, "nvram_chksum_algo_config.c", "w+")
+        printf(COPYRIGHTS_HEADER % "nvram_chksum_algo_config.c", file=fd, end="")
+        printf("#include \"custom_nvram_sec.h\"\n\n\n", file=fd, end="")
+        if global_value.macro & const_value.__NVRAM_UT_TEST__:
+            printf("nvram_checksum_config NVRAM_CHK_CONFIG = \n", file=fd, end="")
+        else:
+            printf("const nvram_checksum_config NVRAM_CHK_CONFIG = \n", file=fd, end="")
+        printf("    {\n", file=fd, end="")
+        printf("       %d, %s, %d, %s\n" % (global_value.enhance_size, nvram_algo_type[global_value.enhance_type],
+                                            global_value.default_size, nvram_algo_type[global_value.default_type]),
+                        file=fd, end="")
+        printf("    };", file=fd, end="")
+        fd.close()
+    
+
+
+if __name__ == '__main__':
+    pass
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/sys_cache_generator.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/sys_cache_generator.py
new file mode 100644
index 0000000..03a0e3b
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/sys_cache_generator.py
@@ -0,0 +1,324 @@
+import os
+import re
+import struct
+import sys
+
+from .initconfig import global_value
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import COPYRIGHTS_HEADER
+from .initconfig import autogen_open_file
+from .tableconstructor import read_str_in_binary, offset_elf
+# from .tableconstructor_win import read_str_in_binary_win
+from .initconfig import printf
+
+
+NVRAM_RESTORE_FUNCTION_NAME = '''void nvram_restore_%s_cache(nvram_reset_category_enum category, nvram_app_id_enum app_id, kal_uint8 *buffer)
+{
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    switch(app_id)
+    {
+'''
+NVRAM_AUTO_GEN_COMMENT = "            /* Reset: %s */\n"
+NVRAM_RESTORE_FUNCTION_BREAK = '''
+            if (category == NVRAM_RESET_CERTAIN)
+            {
+                break;
+            }'''
+NVRAM_RESTORE_FUNCTION_TAIL = '''        default:
+        break;
+    }
+}
+
+'''
+
+
+class sys_cache:
+    id = 0
+    app_id = 0
+    restore = 0
+    p_description = 0x00
+    description = ""
+    p_app_id_str = 0x00
+    app_id_str = ""
+    p_id_str = 0x00
+    id_str = ""
+    value = []
+
+
+nvram_sys_cache = []
+nvram_restore_cache_system = []
+nvram_restore_system_idx = []
+
+for i in range(const_value.NVRAM_APP_TOTAL):
+    nvram_restore_system_idx.append(0)
+for i in range(const_value.NVRAM_APP_TOTAL):
+    list = []
+    for j in range(const_value.NVRAM_SYS_CACHE_MAX):
+        list.append(0)
+    nvram_restore_cache_system.append(list)
+
+# win
+def parse_system_cache_win():
+    """ parse system cache in .exe & .map"""
+
+    fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.map", "r")
+    cache_offset = 0
+    cache_total_len_addr = 0
+    for each_line in fd:
+        if re.search("\s+nvram_sys_cache\s+", each_line):
+            s = each_line.strip()
+            list_sys = s.split()
+            cache_offset = int(list_sys[0], base=16)
+            continue
+        if re.search("\s+nvram_sys_cache_length\s+", each_line):
+            s = each_line.strip()
+            list_sys = s.split()
+            cache_total_len_addr = int(list_sys[0], base=16)
+            continue
+    fd.close()
+    # ===
+    global_value.logger.info("cache_offset = 0x%x, cache_total_len_addr = 0x%x", cache_offset, cache_total_len_addr)  
+    if not cache_offset:
+        global_value.logger.debug("cache_offset = 0 ,read nvram_sys_cache error!")  
+        sys.exit(1)
+    if not cache_total_len_addr:
+        global_value.logger.debug("nvram_sys_cache_length = 0 ,read nvram_sys_cache_length error!")  
+        sys.exit(1)
+    # ===
+
+    
+    
+    fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.exe", "rb")
+    offset = offset_elf(cache_total_len_addr)
+    fd.seek(offset)
+    r_bin = fd.read(4)
+    cache_total_len = struct.unpack("I", r_bin)[0]
+    
+    if global_value.target_bit == const_value.TARGET_64BIT:
+        fmt = '2H9B11Q'
+    else:
+        fmt = '2H9B11I'
+    
+    cache_item_len = struct.calcsize(fmt)
+    cache_total_item = cache_total_len // cache_item_len
+    cache_offset = offset_elf(cache_offset)
+    fd.seek(cache_offset)
+    for i in range(cache_total_item):
+        r_bin = fd.read(cache_item_len)
+        s = struct.unpack(fmt, r_bin)
+        one_entry = sys_cache()
+        one_entry.id = s[0]
+        one_entry.app_id = s[1]
+        one_entry.restore = s[2]
+        list = []
+        for j in range(3, 3 + 8):
+            list.append(s[j])
+        one_entry.value = list
+        one_entry.p_id_str = s[11]
+        one_entry.p_app_id_str = s[12]
+        one_entry.p_description = s[21]
+        nvram_sys_cache.append(one_entry)
+    
+    for i in range(len(nvram_sys_cache)):
+        item = nvram_sys_cache[i]
+        item.description = read_str_in_binary(fd, item.p_description)
+        item.app_id_str = read_str_in_binary(fd, item.p_app_id_str)
+        item.id_str = read_str_in_binary(fd, item.p_id_str)
+    fd.close()
+    
+    
+    
+
+def parse_system_cache():
+    """ parse system cache in .elf&.map"""
+    # fd = open(os.path.join(global_value.path, "nvram_auto_gen", "nvram_auto_gen_target.map"), "r")
+    fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.map", "r")
+    for each_line in fd:
+        
+        if re.search("\s+nvram_sys_cache\s+", each_line):
+            s = each_line.strip()
+            # list_sys = re.split("\W+", s)
+            list_sys = s.split()
+            cache_offset = int(list_sys[0], base=16)
+            cache_total_len = int(list_sys[4], base=16)
+            break
+    fd.close()
+    # ===
+    global_value.logger.info("cache_offset = 0x%x, cache_total_len = 0x%x", cache_offset, cache_total_len)  
+    if not cache_offset:
+        global_value.logger.debug("cache_offset = 0 ,read nvram_sys_cache error!")  
+        sys.exit(1)
+    if not cache_total_len:
+        global_value.logger.debug("cache_total_len = 0 ,read nvram_sys_cache error!")  
+        sys.exit(1)
+    # ===
+
+    cache_item_len = struct.calcsize('2H9B11I')
+    cache_total_item = cache_total_len // cache_item_len
+    # cache_offset = cache_offset - global_value.data_lma + global_value.data_off
+    cache_offset = offset_elf(cache_offset)
+    # fd = open(os.path.join(global_value.path, "nvram_auto_gen", "nvram_auto_gen_target"), "rb")
+    fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target", "rb")
+    fd.seek(cache_offset)
+    for i in range(cache_total_item):
+        r_bin = fd.read(cache_item_len)
+        s = struct.unpack('2H9B11I', r_bin)
+        one_entry = sys_cache()
+        one_entry.id = s[0]
+        one_entry.app_id = s[1]
+        one_entry.restore = s[2]
+        list = []
+        for j in range(3, 3 + 8):
+            list.append(s[j])
+        one_entry.value = list
+        one_entry.p_id_str = s[11]
+        one_entry.p_app_id_str = s[12]
+        one_entry.p_description = s[21]
+        nvram_sys_cache.append(one_entry)
+
+    for i in range(len(nvram_sys_cache)):
+        item = nvram_sys_cache[i]
+        item.description = read_str_in_binary(fd, item.p_description)
+        item.app_id_str = read_str_in_binary(fd, item.p_app_id_str)
+        item.id_str = read_str_in_binary(fd, item.p_id_str)
+    fd.close()
+
+
+
+def nvram_gen_check_sys_cache(fh_file):
+    """ output system cache default value to custom_nvram_restore.c"""
+    # Local Variables
+    byte_idx = 0
+    bit_idx = 0
+    data = nvram_sys_cache[const_value.NVRAM_SYS_CACHE_BEGIN - 1].value
+
+    # Code Body
+    for loop_idx in range(const_value.NVRAM_SYS_CACHE_BEGIN, const_value.NVRAM_SYS_CACHE_MAX):
+        if nvram_sys_cache[loop_idx].id != loop_idx + 1:
+            global_value.logger.error("please check nvram_data_item.h and nvram_data_item.c: # sys cache enum (%d) "
+                                      "and # sys cache entry must sync.", loop_idx)
+            sys.exit(3)
+        byte_idx = loop_idx // 8
+        bit_idx = loop_idx % 8
+        if nvram_sys_cache[loop_idx].restore:
+            data[byte_idx] |= (0x1 << 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] += 1
+    # step 1:generate restore mark
+    printf("kal_uint8 const NVRAM_EF_SYS_CACHE_OCTET_DEFAULT[NVRAM_EF_SYS_CACHE_OCTET_TOTAL * "
+          "NVRAM_EF_SYS_CACHE_OCTET_SIZE] =\n{", file=fh_file)
+    # step 2:generate default value
+    for loop_idx in range(const_value.NVRAM_SYS_CACHE_BEGIN, const_value.NVRAM_SYS_CACHE_MAX):
+        for loop_value_idx in range(struct.calcsize('d')):
+            printf("    0x%02X, " % nvram_sys_cache[loop_idx - 1].value[loop_value_idx], file=fh_file, end="")
+        printf("", file=fh_file)
+    # step 3:generate last
+    for loop_value_idx in range(struct.calcsize('d') - 1):
+        printf("    0x%02X, " % nvram_sys_cache[const_value.NVRAM_SYS_CACHE_MAX - 1].value[loop_value_idx], file=fh_file,
+              end="")
+    printf("    0x%02X " % nvram_sys_cache[const_value.NVRAM_SYS_CACHE_MAX - 1].value[7], file=fh_file, end="")
+    printf("", file=fh_file)
+    printf("};", file=fh_file)
+
+
+def nvram_gen_sys_cache_res_func(fh_file):
+    """ output system cache restore fun to custom_nvram_restore.c """
+    printf(NVRAM_RESTORE_FUNCTION_NAME % "system", file=fh_file, end="")
+    for loop_app_idx in range(const_value.NVRAM_APP_TOTAL):
+        if nvram_restore_system_idx[loop_app_idx]:
+            printf("        case %s :\n" % nvram_sys_cache[nvram_restore_cache_system[loop_app_idx][0]].app_id_str,
+                  file=fh_file, end="")
+        else:
+            continue
+        for loop_app_cache_idx in range(nvram_restore_system_idx[loop_app_idx]):
+            printf(NVRAM_AUTO_GEN_COMMENT % nvram_sys_cache[
+                nvram_restore_cache_system[loop_app_idx][loop_app_cache_idx]].description,
+                  file=fh_file, end="")
+            for loop_value_idx in range(struct.calcsize('d')):
+                printf("            buffer[%d * (%s - 1) + %d] = 0x%02X;\n" % (
+                    struct.calcsize('d'),
+                    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]].value[loop_value_idx]
+                ),
+                      file=fh_file, end="")
+        printf(NVRAM_RESTORE_FUNCTION_BREAK, file=fh_file)
+    printf(NVRAM_RESTORE_FUNCTION_TAIL, file=fh_file)
+
+
+def nvram_gen_restore_dom(fh_file):
+    """ output restore enum to custom_nvram_dom.h """
+    nvram_restore_lid_enum_array = []
+    nvram_restore_lid_description_point = []
+    nvram_max_length_lid_str = 0
+    '''
+    for item in logical_data_item_table:
+        if not (item.category & (const_value.NVRAM_CATEGORY_IMPORTANT_L1 | const_value.NVRAM_CATEGORY_IMPORTANT_L4)):
+            if len(item.str_LID) > nvram_max_length_lid_str:
+                nvram_max_length_lid_str = len(item.str_LID)
+            nvram_restore_lid_enum_array.append(item.str_LID)
+            nvram_restore_lid_description_point.append(item.description)
+    '''
+    for ldi in logical_data_item_table:
+        if ldi.lid == 0 or ldi.size == 0 or ldi.total_records == 0:
+            continue
+        onefilefssize = (ldi.FileSize + const_value.FS_PAGE_SIZE - 1) // const_value.FS_PAGE_SIZE * const_value.FS_PAGE_SIZE
+        if onefilefssize:
+            if not (ldi.category & (const_value.NVRAM_CATEGORY_IMPORTANT_L1 | const_value.NVRAM_CATEGORY_IMPORTANT_L4)):
+                if len(ldi.str_LID) > nvram_max_length_lid_str:
+                    nvram_max_length_lid_str = len(ldi.str_LID)
+                nvram_restore_lid_enum_array.append(ldi.str_LID)
+                nvram_restore_lid_description_point.append(ldi.description)
+
+
+    printf("/* %s system settings */\n" % "LID", file=fh_file, end="")
+    printf("typedef enum\n{\n", file=fh_file, end="")
+    for loop_app_idx in range(len(nvram_restore_lid_enum_array)):
+        printf("    %s,    " % nvram_restore_lid_enum_array[loop_app_idx], file=fh_file, end="")
+        for loop_space in range(nvram_max_length_lid_str - len(nvram_restore_lid_enum_array[loop_app_idx])):
+            printf(" ", file=fh_file, end="")
+        if nvram_restore_lid_description_point[loop_app_idx] == "null":
+            printf("/* (%s) */\n" % nvram_restore_lid_description_point[loop_app_idx], file=fh_file, end="")
+        else:
+            printf("/* %s */\n" % nvram_restore_lid_description_point[loop_app_idx], file=fh_file, end="")
+    printf("    NVRAM_LAST_%s_ELEMENT\n}%sDATA;\n\n" % ("LID", "LID"), file=fh_file, end="")
+
+
+def nvram_gen_restore_function():
+    """ gen file: custom_nvram_restore.c / nvram_restore_dom_new.h"""
+    # if sys.platform.count("linux") == 0:
+    if global_value.platform == "Windows":
+        parse_system_cache_win()
+    else:
+        parse_system_cache()
+    # ----------------------------------
+    # gen custom_nvram_restore.c
+    # fd_restore_factory_c = open(os.path.join(global_value.path, "nvram_auto_gen", "custom_nvram_restore.c"), "w+")
+    fd_restore_factory_c = autogen_open_file(global_value.autogen_path, "custom_nvram_restore.c", "w+")
+    printf(COPYRIGHTS_HEADER % "nvram_user_restore_factory.h", file=fd_restore_factory_c)
+
+    printf("#ifndef NVRAM_NOT_PRESENT", file=fd_restore_factory_c)
+    printf("#include \"kal_general_types.h\"", file=fd_restore_factory_c)
+    printf("#include \"nvram_enums.h\"", file=fd_restore_factory_c)
+    printf("#include \"custom_nvram_config.h\"", file=fd_restore_factory_c)
+    printf("#include \"nvram_data_items.h\"", file=fd_restore_factory_c)
+
+    nvram_gen_check_sys_cache(fd_restore_factory_c)
+    nvram_gen_sys_cache_res_func(fd_restore_factory_c)
+    printf("#endif /* NVRAM_NOT_PRESENT */", file=fd_restore_factory_c)
+    fd_restore_factory_c.close()
+
+    # -----------------------------------------
+    # gen custom_nvram_dom.h
+    # fd_restore_dom_h = open(os.path.join(global_value.path, "nvram_auto_gen", "nvram_restore_dom.h"), "w+")
+    fd_restore_dom_h = autogen_open_file(global_value.autogen_path, "nvram_restore_dom.h", "w+")
+    nvram_gen_restore_dom(fd_restore_dom_h)
+    fd_restore_dom_h.close()
+
+
+if __name__ == '__main__':
+    nvram_gen_restore_function()
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/tableconstructor.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/tableconstructor.py
new file mode 100644
index 0000000..9d9e78d
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/tableconstructor.py
@@ -0,0 +1,646 @@
+import struct
+import logging
+import platform
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import global_value
+from .initconfig import LtableEntry, get_checksum_size
+from .initconfig import autogen_open_file, nvram_algo_type, nvram_algo_type_str
+import re
+import os
+import sys, json
+from time import time
+from collections import OrderedDict
+
+
+def pars_segment_info():
+    global_value.logger.info("===== pars_segment_info begin =====")
+    fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.map", "r")
+    p_custom_algo_addr = 0
+    for each_line in fd:
+        if re.match("\s*\d+\s+\.rodata", each_line ):
+            s = each_line.strip()  # clear head&tail character ('\n' ' ' '\t' '\r')
+            list_rodata = s.split()  # split ("" " " "\n" "\t")
+            global_value.rodata_lma = int(list_rodata[4], base=16)
+            global_value.rodata_off = int(list_rodata[5], base=16)
+        elif re.match("\s*\d+\s+\.data", each_line ):
+            s = each_line.strip()  
+            list_data = s.split()  
+            global_value.data_lma = int(list_data[4], base=16)
+            global_value.data_off = int(list_data[5], base=16)
+        elif re.match("\s*\d+\s+\.bss", each_line ):
+            s = each_line.strip()  
+            list_data = s.split()  
+            global_value.bss_lma = int(list_data[4], base=16)
+            global_value.bss_off = int(list_data[5], base=16)
+        elif re.match("\s*\d+\s+NVRAM_LTABLE", each_line ):
+            s = each_line.strip()  
+            list_t = s.split()  
+            global_value.table_offset = int(list_t[5], base=16)
+            global_value.table_len = int(list_t[2], base=16)
+        elif re.search("\s+nvram_long_length\s+", each_line ):
+            s = each_line.strip()
+            list_t = s.split()
+            global_value.nvram_long_length = int(list_t[4], base=16)
+        elif re.search("\s+nvram_ptr_length\s+", each_line ):
+            s = each_line.strip()
+            list_t = s.split()
+            global_value.nvram_ptr_length = int(list_t[4], base=16)
+        elif re.search("\s+nvram_padding_length\s+", each_line ):
+            s = each_line.strip()
+            list_t = s.split()
+            global_value.nvram_padding_length = int(list_t[4], base=16)
+        elif re.search("\s+nvram_ltable_entry_length\s+", each_line ):
+            s = each_line.strip()
+            list_t = s.split()
+            global_value.nvram_ltable_entry_length = int(list_t[4], base=16)
+        elif re.search("\s+NVRAM_EF_ZERO_DEFAULT\s+", each_line ):
+            s = each_line.strip()
+            list_t = s.split()
+            const_value.NVRAM_EF_ZERO_DEFAULT = int(list_t[0], base=16)
+            continue
+        elif re.search("\s+NVRAM_EF_FF_DEFAULT\s+", each_line ):
+            s = each_line.strip()
+            list_t = s.split()
+            const_value.NVRAM_EF_FF_DEFAULT = int(list_t[0], base=16)
+            continue
+        elif re.search("\s+NVRAM_EF_SPECIAL_DEFAULT\s+", each_line ):
+            s = each_line.strip()
+            list_t = s.split()
+            const_value.NVRAM_EF_SPECIAL_DEFAULT = int(list_t[0], base=16)
+            continue
+        elif global_value.macro & const_value.__NV_CHKSUM_ENHANCE__ and re.search("\s+CUSTOM_CHK_ALGO_CONFIG\s+", each_line ):
+            s = each_line.strip()
+            list_t = s.split()
+            p_custom_algo_addr = int(list_t[0], base=16)
+            continue
+    
+    fd.close()
+    
+    global_value.logger.info("rodata_lma = 0x%x, rodata_off = 0x%x", global_value.rodata_lma, global_value.rodata_off)
+    global_value.logger.info("data_lma = 0x%x, data_off = 0x%x", global_value.data_lma, global_value.data_off)
+    global_value.logger.info("bss_lma = 0x%x, bss_off = 0x%x", global_value.bss_lma, global_value.bss_off)
+    global_value.logger.info("table_offset = 0x%x, table_len = 0x%x, nvram_ltable_entry_length = 0x%x", global_value.table_offset,
+                             global_value.table_len, global_value.nvram_ltable_entry_length)
+    global_value.logger.info("nvram_long_length = %d nvram_ptr_length = %d nvram_padding_length = %d",
+                             global_value.nvram_long_length, global_value.nvram_ptr_length,
+                             global_value.nvram_padding_length)
+    global_value.logger.info("p_NVRAM_EF_ZERO_DEFAULT = 0x%x", const_value.NVRAM_EF_ZERO_DEFAULT)
+    global_value.logger.info("p_NVRAM_EF_FF_DEFAULT = 0x%x", const_value.NVRAM_EF_FF_DEFAULT)
+    global_value.logger.info("p_NVRAM_EF_SPECIAL_DEFAULT = 0x%x", const_value.NVRAM_EF_SPECIAL_DEFAULT)
+    global_value.logger.info("p_custom_algo_addr = 0x%x", p_custom_algo_addr)
+    
+    # ===
+    # check read .map , show error log
+    if (not global_value.rodata_lma) or (not global_value.rodata_off):
+        global_value.logger.error("rodata_lma = 0 or rodata_off = 0 ,read .rodata error!")
+        sys.exit(1)
+    if (not global_value.data_lma) or (not global_value.data_off):
+        global_value.logger.error("data_lma = 0 or data_off = 0 ,read .data error!")
+        sys.exit(1)    
+    if (not global_value.bss_lma) or (not global_value.bss_off):
+        global_value.logger.error("bss_lma = 0 or bss_off = 0 ,read .bss error!")
+        sys.exit(1)    
+    if (not global_value.table_offset) or (not global_value.table_len):
+        global_value.logger.error("table_offset = 0 or table_len = 0 ,read NVRAM_LTABLE error!")
+        sys.exit(1)    
+    if not global_value.nvram_ltable_entry_length:
+        global_value.logger.error("nvram_ltable_entry_length = 0 ,read nvram_ltable_entry_length error!")
+        sys.exit(1)    
+    if not const_value.NVRAM_EF_ZERO_DEFAULT:
+        global_value.logger.error("NVRAM_EF_ZERO_DEFAULT = 0 ,read NVRAM_EF_ZERO_DEFAULT error!")
+        sys.exit(1)    
+    if not const_value.NVRAM_EF_FF_DEFAULT:
+        global_value.logger.error("NVRAM_EF_FF_DEFAULT = 0 ,read NVRAM_EF_FF_DEFAULT error!")
+        sys.exit(1)
+    if not const_value.NVRAM_EF_SPECIAL_DEFAULT:
+        global_value.logger.error("NVRAM_EF_SPECIAL_DEFAULT = 0 ,read NVRAM_EF_SPECIAL_DEFAULT error!")
+        sys.exit(1)
+    # ===
+    
+    fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target", "rb")
+    # check target 64bit or 32bit
+    fd.seek(const_value.LINUX_BIT_ADDR)
+    b = fd.read(1)
+    if type(b) == str: # python 2
+        bit_data = ord(b)
+    else:
+        bit_data = int(b[0])
+    
+    if bit_data == const_value.LINUX_64BIT_DATA:  # 64bit
+        global_value.target_bit = const_value.TARGET_64BIT
+        global_value.logger.debug("Linux target is 64bit! ")
+    elif bit_data == const_value.LINUX_32BIT_DATA:  # 32bit
+        global_value.target_bit = const_value.TARGET_32BIT
+        global_value.logger.debug("Linux target is 32bit! ")
+    else:
+        global_value.logger.debug("check Linux bit error! bit_data = 0x%x", bit_data)
+        sys.exit(1)
+    fd.close()
+    
+    # ===========
+    # read custom algo config
+    if global_value.macro & const_value.__NV_CHKSUM_ENHANCE__:
+        fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target", "rb")
+        if not p_custom_algo_addr:
+            global_value.logger.error("read CUSTOM_CHK_ALGO_CONFIG for map error!")
+            sys.exit(1)
+        custom_algo_offset = offset_elf(p_custom_algo_addr)
+        fd.seek(custom_algo_offset)
+        size = struct.calcsize("4I")
+        b = fd.read(size)
+        s = struct.unpack("4I", b)
+        global_value.enhance_size = s[0]
+        global_value.enhance_type = s[1]
+        global_value.default_size = s[2]
+        global_value.default_type = s[3]
+        global_value.logger.info("enhance_type = %s enhance_size = %d", nvram_algo_type[global_value.enhance_type], global_value.enhance_size)
+        global_value.logger.info("default_type = %s default_size = %d", nvram_algo_type[global_value.default_type], global_value.default_size)
+        fd.close()
+     
+    global_value.logger.info("===== pars_segment_info end =====")
+    
+    
+def offset_elf(offset):
+    if platform.system() == "Windows":   # windows
+        if offset < global_value.data_addr:  # .text
+            offset_exe = offset - global_value.image_base - global_value.text_offset
+        else: #elif offset < global_value.bss_addr: # .data
+            offset_exe = offset - global_value.image_base - global_value.data_offset
+        return offset_exe
+    else:
+        if offset < global_value.data_lma:
+            offset_elf = offset - global_value.rodata_lma + global_value.rodata_off
+        else: #elif offset < global_value.bss_lma:
+            offset_elf = offset - global_value.bss_lma + global_value.bss_off
+        return offset_elf
+
+    
+def parse_lid_table():
+    """ read ldi table from exe/elf """
+    # -------------------------------------------------
+    # generate struct.unpack fmt by parse .map and .elf
+    global_value.logger.info("===== parse_lid_table begin =====")
+    
+    entry_table_file = os.path.join(global_value.autogen_path, "entry_tables.json")
+    if os.path.exists(entry_table_file):
+        # reuse entry generated by NVDB
+        zero_default = u"00"
+        ff_default = u"ff"
+        special_default = u"55"
+        
+        with open(entry_table_file, "r") as fh:
+            entry_data = json.load(fh)
+        
+        for entry in entry_data:
+            entry_obj = LtableEntry()
+            entry_obj.lid = entry["LID"]
+            entry_obj.total_records = entry["total_records"]
+            entry_obj.size = entry["size"]
+            # one_entry.p_str_default_value = var[3]
+            #one_entry.p_default_value = var[4]
+            entry_obj.category = entry["category"]
+            entry_obj.attr = entry["attr"]
+            entry_obj.FilePrefix = entry["fileprefix"]
+            entry_obj.FileVerno = entry["fileverno"]
+            entry_obj.str_LID = entry["str_LID"]
+            entry_obj.description = entry["description"]
+            # handle default value
+            if entry["default_value"].isalnum():
+                d_val = entry["default_value"]
+                if entry_obj.attr & const_value.NVRAM_ATTR_MULTI_DEFAULT:
+                    entry_obj.default_value_len = entry_obj.size * entry_obj.total_records
+                else:
+                    entry_obj.default_value_len = entry_obj.size
+                if d_val in (zero_default, ff_default, special_default):       # workaround for custpack default value
+                    entry_obj.default_value_len = 1
+                entry_obj.default_value = [int(d_val[index-2: index], 16) for index in range(2, len(d_val)+1, 2)]
+            elif entry["default_value"] in "NVRAM_EF_ZERO_DEFAULT":
+                entry_obj.p_default_value = const_value.NVRAM_EF_ZERO_DEFAULT
+            elif entry["default_value"] == "NVRAM_EF_FF_DEFAULT":
+                entry_obj.p_default_value = const_value.NVRAM_EF_FF_DEFAULT
+                # entry_obj.default_value = ['FF']
+            else:
+                entry_obj.str_default_value = entry["default_value"]
+            if "hash_key" in entry:
+                entry_obj.hash_key = entry["hash_key"]
+            #if (global_value.macro & const_value.__NVRAM_LID_HASH_CHECK__) and (global_value.macro & const_value.__MTK_INTERNAL__):
+            #    one_entry.hash_key = var[11]
+            logical_data_item_table.append(entry_obj)
+    else:
+        fd_map = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.map", "r")
+        if platform.system() == "Windows":   # windows
+            fd_elf = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.exe", "rb")
+        else:
+            fd_elf = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target", "rb")
+        
+        fmt = gen_unpack_fmt(fd_map, fd_elf, global_value.nvram_ltable_entry_length)
+        fd_map.close()
+        global_value.logger.info("unpack fmt = %s", fmt)
+        
+        # -------------------------------------------------
+        # parse lid_table
+        table_total_item = global_value.table_len // global_value.nvram_ltable_entry_length
+        fd_elf.seek(global_value.table_offset)
+        for i in range(table_total_item):
+            r_bin = fd_elf.read(global_value.nvram_ltable_entry_length)
+            var = struct.unpack(fmt, r_bin)
+            one_entry = LtableEntry()
+            one_entry.lid = var[0]
+            one_entry.total_records = var[1]
+            one_entry.size = var[2]
+            one_entry.p_str_default_value = var[3]
+            one_entry.p_default_value = var[4]
+            one_entry.category = var[5]
+            one_entry.attr = var[6]
+            one_entry.FilePrefix = var[7].decode("ascii")[:-1]
+            one_entry.FileVerno = var[8].decode("ascii")[:-1]
+            one_entry.p_str_LID = var[9]
+            one_entry.p_description = var[10]
+            if (global_value.macro & const_value.__NVRAM_LID_HASH_CHECK__) and (global_value.macro & const_value.__MTK_INTERNAL__):
+                one_entry.hash_key = var[11]
+            # ---------------
+            logical_data_item_table.append(one_entry)
+    
+    for i, ldi in enumerate(logical_data_item_table):
+        global_value.logger.debug("%d lid = %d size = %d total = %d", i, ldi.lid, ldi.size, ldi.total_records)
+
+    
+    global_value.logger.info("===== parse_lid_table end =====")
+
+def get_oft_data(fd_map, fd_elf, map_name):
+    """ get real data from map_name """
+    fd_map.seek(0)
+    addr = 0x0
+    find_data = "\s+" + map_name + "\s+"
+    for each_line in fd_map:
+        if re.search(find_data, each_line):
+            s = each_line.strip()
+            list_t = s.split()
+            addr = int(list_t[0], base=16)
+            break
+    if addr == 0:
+        global_value.logger.debug("==== get_oft_data() ====")
+        global_value.logger.debug("find_data = %s", find_data)
+        global_value.logger.error("%s not found in .map ", map_name)
+        sys.exit(1)
+    if check_bss(addr):     # bss 
+        return 0x0
+    offset_for_elf = offset_elf(addr)   
+    
+    # read oft_data
+    fd_elf.seek(offset_for_elf)
+    bin_s = fd_elf.read(2)
+    fmt = "H"
+    offset_data = struct.unpack(fmt, bin_s)[0]
+    return offset_data
+       
+def gen_unpack_fmt(fd_map, fd_elf, ltable_entry_len):
+    """ generate struct.unpack fmt by parse .map and .elf """
+    # define variables
+    ent_fmt = ""
+    pad_str = "x"   # padding fmt
+    # big_endian = ">"
+    # little_endian = "<"
+    ent_stu_list = [    
+        {"map_name": "ent_oft_lid",     "oft_data": 0, "fmt": "H",  "fmt_size": 2},
+        {"map_name": "ent_oft_trecords","oft_data": 0, "fmt": "H",  "fmt_size": 2},
+        {"map_name": "ent_oft_size",    "oft_data": 0, "fmt": "I",  "fmt_size": 4},
+        {"map_name": "ent_oft_str_dval","oft_data": 0, "fmt": "I",  "fmt_size": 4},
+        {"map_name": "ent_oft_d_val",   "oft_data": 0, "fmt": "I",  "fmt_size": 4},
+        {"map_name": "ent_oft_cate",    "oft_data": 0, "fmt": "I",  "fmt_size": 4},
+        {"map_name": "ent_oft_attr",    "oft_data": 0, "fmt": "I",  "fmt_size": 4},
+        {"map_name": "ent_oft_fprefix", "oft_data": 0, "fmt": "5s", "fmt_size": 5},
+        {"map_name": "ent_oft_fverno",  "oft_data": 0, "fmt": "4s", "fmt_size": 4},
+        {"map_name": "ent_oft_s_lid",   "oft_data": 0, "fmt": "I",  "fmt_size": 4},
+        {"map_name": "ent_oft_desc",    "oft_data": 0, "fmt": "I",  "fmt_size": 4},
+    ]
+    if (global_value.macro & const_value.__NVRAM_LID_HASH_CHECK__) and (global_value.macro & const_value.__MTK_INTERNAL__):
+        global_value.logger.info("nvram lid hash check  open")
+        ent_off_item = {"map_name": "ent_oft_hash",    "oft_data": 0, "fmt": "I",  "fmt_size": 4}
+        ent_stu_list.append(ent_off_item)
+    else:
+        global_value.logger.info("hash check disabled")
+        
+    # default 32bit
+    if global_value.target_bit == const_value.TARGET_64BIT:
+        ent_stu_list[3]["fmt"] = "Q"        # p_str_default_value
+        ent_stu_list[3]["fmt_size"] = 8
+        ent_stu_list[4]["fmt"] = "Q"        # p_default_value
+        ent_stu_list[4]["fmt_size"] = 8
+        ent_stu_list[9]["fmt"] = "Q"        # p_str_LID
+        ent_stu_list[9]["fmt_size"] = 8
+        ent_stu_list[10]["fmt"] = "Q"       # p_description
+        ent_stu_list[10]["fmt_size"] = 8
+    
+    
+    
+    for each_list in ent_stu_list:
+        each_list["oft_data"] = get_oft_data(fd_map, fd_elf, each_list["map_name"])
+    
+    real_offset = 0
+    for i in range(len(ent_stu_list)):
+        dict_data = ent_stu_list[i]
+        item_offset = dict_data["oft_data"]
+        item_fmt = dict_data["fmt"]
+        item_size = dict_data["fmt_size"]
+        
+        if real_offset == item_offset:
+            ent_fmt += item_fmt
+            real_offset += item_size
+        elif real_offset < item_offset:     # padding exists
+            padding_size = item_offset - real_offset
+            for j in range(padding_size):   # add padding
+                ent_fmt += pad_str
+                real_offset += 1
+            ent_fmt += item_fmt
+            real_offset += item_size
+        else:   # real_offset > item_offset => error
+            global_value.logger.error("ent_fmt = %s, real_offset = %d, item_offset = %d item_size = %d",
+                                  ent_fmt, real_offset, item_offset, item_size)
+            for j in range(len(ent_stu_list)):
+                data = ent_stu_list[j]
+                global_value.logger.debug("map_name = %s oft_data = %d, fmt = %s fmt_size = %d",
+                                  data["map_name"], data["oft_data"], data["fmt"], data["fmt_size"])
+            sys.exit(1)
+    
+    return ent_fmt
+    
+    
+def read_binary_to_str(fd, offset):
+    """ binary to str"""
+    strs = ""
+    fd.seek(offset)
+    b = fd.read(1)
+    if type(b) == str: # python 2
+        while b != "\x00":
+            strs += b
+            b = fd.read(1)
+    else:  # python 3
+        while int(b[0]) != 0:
+            strs += chr(b[0])
+            b = fd.read(1)
+    return strs
+
+
+
+def read_str_in_binary(fd, addr):
+    offset = offset_elf(addr)
+    strs = read_binary_to_str(fd, offset)
+    return strs
+    
+
+def nvram_util_make_lid_filename(attr, fileprefix, fileverno, first_copy):
+    """ Get nvram file name"""
+    nvram_name = ""
+    if attr & const_value.NVRAM_ATTR_MULTIPLE:
+        if first_copy:
+            nvram_name = fileprefix + "A" + fileverno
+        else:
+            nvram_name = fileprefix + "B" + fileverno
+    else:
+        nvram_name = fileprefix + "_" + fileverno
+
+    return nvram_name
+
+
+def nvram_query_file_name(category, nvram_name):
+    """ Get file full name """
+    if (global_value.macro & const_value.__NVRAM_UT_TEST__) and (not global_value.macro & const_value.__NVRAM_LID_CACHE__):
+        if category & const_value.NVRAM_CATEGORY_INTERNAL:  # CORE
+            src_path = const_value.NVRAM_TEST_FS_COREITEM_PATH + "\\\\" + nvram_name
+        elif category & const_value.NVRAM_CATEGORY_CALIBRAT:  # CALI
+            src_path = const_value.NVRAM_TEST_FS_CALIBRAT_DATAITEM_PATH + "\\\\" + nvram_name
+        elif category & const_value.NVRAM_CATEGORY_IMPORTANT:  # IMPT
+            src_path = const_value.NVRAM_TEST_FS_IMPT_DATAITEM_PATH + "\\\\" + nvram_name
+        elif (category & const_value.NVRAM_CATEGORY_IMPORTANT_L4) and (global_value.macro & const_value.__CCCIFS_SUPPORT__):  # IMPNT
+            if global_value.macro & (const_value.__MTK_TARGET__ | const_value.__NVRAM_IMPORTANT_PARTIONS__ | const_value.__CCCIFS_SUPPORT__):
+                src_path = "X:\\\\NV_TEST\\\\" + nvram_name
+            else:
+                src_path = const_value.NVRAM_TEST_FS_IMPORTNT_DATAITEM_PATH + "\\\\" + nvram_name
+        elif (category & const_value.NVRAM_CATEGORY_IMPORTANT_L1) and (global_value.macro & const_value.__CCCIFS_SUPPORT__):  # IMPNT
+            if global_value.macro & (const_value.__MTK_TARGET__ | const_value.__NVRAM_IMPORTANT_PARTIONS__ | const_value.__CCCIFS_SUPPORT__):
+                src_path = "X:\\\\NV_TEST\\\\" + nvram_name
+            else:
+                src_path = const_value.NVRAM_TEST_FS_IMPORTNT_DATAITEM_PATH + "\\\\" + nvram_name
+        elif (category & const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE) and (global_value.macro & const_value.__NVRAM_CUSTOM_SENSITIVE__):  # CUST
+            src_path = const_value.NVRAM_FS_CUST_DATAITEM_PATH + "\\\\" + nvram_name
+        else:  # DATA
+            src_path = const_value.NVRAM_TEST_FS_DATAITEM_PATH + "\\\\" + nvram_name
+    else:
+        if category & const_value.NVRAM_CATEGORY_INTERNAL:  # CORE
+            src_path = const_value.NVRAM_FS_COREITEM_PATH + "\\\\" + nvram_name
+        elif category & const_value.NVRAM_CATEGORY_CALIBRAT:  # CALI
+            src_path = const_value.NVRAM_FS_CALIBRAT_DATAITEM_PATH + "\\\\" + nvram_name
+        elif category & const_value.NVRAM_CATEGORY_IMPORTANT:  # IMPT
+            src_path = const_value.NVRAM_FS_IMPT_DATAITEM_PATH + "\\\\" + nvram_name
+        elif (category & const_value.NVRAM_CATEGORY_IMPORTANT_L4) and (global_value.macro & const_value.__CCCIFS_SUPPORT__):  # IMPNT
+            if global_value.macro & (const_value.__MTK_TARGET__ | const_value.__NVRAM_IMPORTANT_PARTIONS__ | const_value.__CCCIFS_SUPPORT__):
+                src_path = "X:\\\\" + nvram_name
+            else:
+                src_path = const_value.NVRAM_FS_IMPORTNT_DATAITEM_PATH + "\\\\" + nvram_name
+        elif (category & const_value.NVRAM_CATEGORY_IMPORTANT_L1) and (global_value.macro & const_value.__CCCIFS_SUPPORT__):  # IMPNT
+            if global_value.macro & (const_value.__MTK_TARGET__ | const_value.__NVRAM_IMPORTANT_PARTIONS__ | const_value.__CCCIFS_SUPPORT__):
+                src_path = "X:\\\\" + nvram_name
+            else:
+                src_path = const_value.NVRAM_FS_IMPORTNT_DATAITEM_PATH + "\\\\" + nvram_name
+        elif (category & const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE) and (global_value.macro & const_value.__NVRAM_CUSTOM_SENSITIVE__):  # CUST
+            src_path = const_value.NVRAM_FS_CUST_DATAITEM_PATH + "\\\\" + nvram_name
+        else:  # DATA
+            src_path = const_value.NVRAM_FS_DATAITEM_PATH + "\\\\" + nvram_name
+
+    return src_path
+
+
+def path_finder(ldi):
+    """ Get lid filepath"""
+    # set secupack FilePrefix in "ST**"
+    if ldi.category & const_value.NVRAM_CATEGORY_SECUPACK:
+        prefix_temp = "ST" + ldi.FilePrefix[2:]
+        nvram_name = nvram_util_make_lid_filename(ldi.attr, prefix_temp, ldi.FileVerno, True)
+    else:
+        nvram_name = nvram_util_make_lid_filename(ldi.attr, ldi.FilePrefix, ldi.FileVerno, True)
+    src_path = nvram_query_file_name(ldi.category, nvram_name)
+    return src_path
+
+
+def file_size_collector(ldi):
+    if global_value.macro & const_value.__NV_CHKSUM_ENHANCE__:
+        if ldi.attr & const_value.NVRAM_ATTR_CHKSM_ENHNC_ALGRTHM:
+            if global_value.enhance_type == nvram_algo_type_str["NVRAM_MD5"]:
+                nvram_checksum_size = const_value.NVRAM_CHKSUM_SIZE
+            else:
+                nvram_checksum_size = global_value.enhance_size
+        else:
+            if global_value.default_type == nvram_algo_type_str["NVRAM_MD5"]:
+                nvram_checksum_size = const_value.NVRAM_CHKSUM_SIZE
+            else:
+                nvram_checksum_size = global_value.default_size
+    else:
+        nvram_checksum_size = const_value.NVRAM_CHKSUM_SIZE
+
+    """ Get file size """
+    if (ldi.attr & const_value.NVRAM_ATTR_CONFIDENTIAL) or (ldi.attr & const_value.NVRAM_ATTR_MSP and global_value.macro & const_value.__NVRAM_BIND_TO_CHIP_CIPHER__):
+        remainLen = (~(ldi.size + nvram_checksum_size) + 1) & (const_value.NVRAM_MSP_ALIGNMENT - 1)
+        onefilesize = (
+                                  ldi.size + nvram_checksum_size + remainLen) * ldi.total_records + const_value.NVRAM_LDI_HEADER_SIZE
+    else:
+        onefilesize = (ldi.size + nvram_checksum_size) * ldi.total_records + const_value.NVRAM_LDI_HEADER_SIZE
+    
+    if ldi.attr & const_value.NVRAM_ATTR_CHKSUM_INTEGRATE:
+        # global_value.logger.debug("checksum integrate: lid: %s", ldi.str_LID)
+        onefilesize = onefilesize + const_value.NVRAM_LDI_APPENDIX_HEADER_SIZE + nvram_checksum_size * ldi.total_records
+    
+    return onefilesize
+
+
+def statistic_lid_item_data():
+    """ statistic cuspack/secupack/otp/sds/auto_pack total&size """
+    global_value.logger.info("===== statistic_lid_item_data begin =====")
+    global_value.custpack_total_to_verify = 0
+    global_value.secupack_total_to_verify = 0
+    global_value.secupack_size_to_verify = 0
+    global_value.otp_total_to_verify = 0
+    global_value.otp_size_to_verify = 0
+    global_value.sds_total_to_verify = 0
+    global_value.sds_size_to_verify = 0
+    global_value.nvram_auto_package_num = 0
+    global_value.nvram_auto_pack_file_offset = 0
+
+    for ldi in logical_data_item_table:
+        nvram_checksum_size = get_checksum_size(ldi)
+        # calculate the custpack
+        if ldi.category & const_value.NVRAM_CATEGORY_CUSTPACK:
+            global_value.custpack_total_to_verify += 1
+        # calculate the secupack
+        if ldi.category & const_value.NVRAM_CATEGORY_SECUPACK:
+            global_value.secupack_total_to_verify += 1
+            if ldi.attr & const_value.NVRAM_ATTR_MULTI_DEFAULT:
+                global_value.secupack_size_to_verify += ldi.size * ldi.total_records + nvram_checksum_size
+            else:
+                global_value.secupack_size_to_verify += ldi.size + nvram_checksum_size
+        # calculate the otp
+        if ldi.category & const_value.NVRAM_CATEGORY_OTP:  # __NVRAM_OTP__
+            global_value.otp_total_to_verify += 1
+            global_value.otp_size_to_verify += ldi.size * ldi.total_records
+        # calculate the vendor reserve size
+        if ldi.category & const_value.NVRAM_CATEGORY_BACKUP_SDS:  # __NVRAM_SECURE_DATA_STORAGE__
+            global_value.sds_total_to_verify += 1
+            global_value.sds_size_to_verify += (ldi.size + nvram_checksum_size +
+                                                ((~(ldi.size + nvram_checksum_size) + 1) & (
+                                                        const_value.NVRAM_MSP_ALIGNMENT - 1))
+                                                ) * ldi.total_records
+        # calcluate the package
+        onefilefssize = (
+                                    ldi.FileSize + const_value.FS_PAGE_SIZE - 1) // const_value.FS_PAGE_SIZE * const_value.FS_PAGE_SIZE
+        if onefilefssize & ldi.attr & const_value.NVRAM_ATTR_PACKAGE:  # __NVRAM_PSEUDO_MERGE__
+            global_value.nvram_auto_package_num += 1
+            global_value.nvram_auto_pack_file_offset += onefilefssize
+    global_value.logger.info("===== statistic_lid_item_data end =====")
+
+"""
+check whether it is bss segment
+in : addr for .map
+out: true, bss segment ; false , not bss segment
+"""
+def check_bss(addr):
+    if platform.system() == "Windows":   # windows
+        if addr >= global_value.bss_addr: # .bss ,write 0x00
+            return True
+        else:
+            return False
+    else:
+        if addr >= global_value.bss_lma:
+            return True
+        else:
+            return False
+        
+            
+def parse_lid_item_data():
+    """ read read data from str_default_value/str_LID/description, caluculate filesize/full path """
+    global_value.logger.info("===== parse_lid_item_data begin =====")
+    entry_table_file = os.path.join(global_value.autogen_path, "entry_tables.json")
+    # NVDB not gen ltable entry, read from map and elf
+    if not os.path.exists(entry_table_file):
+        if platform.system() == "Windows":   # windows
+            fd_target = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.exe", "rb")
+        else:
+            fd_target = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target", "rb")
+        
+        # ---------------------------------------------
+        # parse data item in target.elf
+        for i in range(len(logical_data_item_table)):
+            ldi = logical_data_item_table[i]
+            if ldi.category & const_value.NVRAM_CATEGORY_FUNC_DEFAULT:
+                # parse str_default_value
+                ldi.str_default_value = read_str_in_binary(fd_target, ldi.p_str_default_value)
+            elif ldi.p_default_value != const_value.NVRAM_EF_ZERO_DEFAULT \
+                    and ldi.p_default_value != const_value.NVRAM_EF_FF_DEFAULT \
+                    and ldi.p_default_value != const_value.NVRAM_EF_SPECIAL_DEFAULT:
+                # parse default_value
+                if ldi.attr & const_value.NVRAM_ATTR_MULTI_DEFAULT:
+                    ldi.default_value_len = ldi.size * ldi.total_records
+                else:
+                    ldi.default_value_len = ldi.size
+                
+                list_default_value = []
+                if check_bss(ldi.p_default_value):
+                    for j in range(ldi.default_value_len):
+                        list_default_value.append(0x00)
+                else:
+                    offset = offset_elf(ldi.p_default_value)
+                    fd_target.seek(offset)
+                    b = fd_target.read(ldi.default_value_len)
+                    if type(b[0]) == str: # python 2
+                        list_str = list(b)
+                        for data in list_str:
+                            list_default_value.append(ord(data))
+                    else:  # python 3
+                        list_default_value = list(b)
+                        
+                ldi.default_value = list_default_value
+
+            # parse str_LID
+            ldi.str_LID = read_str_in_binary(fd_target, ldi.p_str_LID)
+            # parse description
+            if ldi.p_description != 0:
+                ldi.description = read_str_in_binary(fd_target, ldi.p_description)
+        fd_target.close()
+    
+    # --------------------------
+    # Get full path & file size
+    for lid in logical_data_item_table:
+        lid.FullPath = path_finder(lid)
+        lid.FileSize = file_size_collector(lid)
+
+        # lid = logical_data_item_table[i]
+        global_value.logger.debug("-------------------------------------------------")
+        global_value.logger.debug("lid = %d total = %d size = %d", lid.lid, lid.total_records, lid.size)
+        global_value.logger.debug("cate = 0x%x attr = 0x%x prefix = %s verno = %s", lid.category, lid.attr,
+                                 lid.FilePrefix, lid.FileVerno)
+        global_value.logger.debug("str_LID = %s str_default_value = %s", lid.str_LID, lid.str_default_value)
+        global_value.logger.debug("description = %s", lid.description)
+        global_value.logger.debug("full path = %s", lid.FullPath)
+        global_value.logger.debug("File Size = %s", lid.FileSize)
+    
+    global_value.logger.info("===== parse_lid_item_data end =====")
+
+def write_logical_table():
+    """write entry table into json file. for NVDB debug use"""
+    logical_table_path = os.path.join(global_value.autogen_path, "autogen_v2_ltables.json")
+    ltable_datas = []
+    for ldi in logical_data_item_table:
+        entry = OrderedDict()
+        entry["LID"] = ldi.lid
+        entry["total_records"] = ldi.total_records
+        entry["size"] = ldi.size
+        entry["category"] = ldi.category
+        entry["attr"] = ldi.attr
+        entry["fileprefix"] = ldi.FilePrefix
+        entry["fileverno"] = ldi.FileVerno
+        entry["str_LID"] = ldi.str_LID
+        entry["hash_key"] = ldi.hash_key
+        ltable_datas.append(entry)
+    with open(logical_table_path, "w") as fh:
+        json.dump(ltable_datas, fh)
+        
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/tableconstructor_win.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/tableconstructor_win.py
new file mode 100644
index 0000000..132ba98
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/tableconstructor_win.py
@@ -0,0 +1,253 @@
+import struct
+import logging
+from .initconfig import logical_data_item_table
+from .initconfig import const_value
+from .initconfig import global_value
+from .initconfig import LtableEntry
+from .initconfig import autogen_open_file, nvram_algo_type
+from .tableconstructor import offset_elf
+import re
+import os
+
+def read_int_in_exe(fd, addr):
+    offset = offset_elf(addr)
+    fd.seek(offset)
+    r_bin = fd.read(4)
+    data = struct.unpack("I", r_bin)[0]
+    return data
+
+
+def parse_segment_info_win():
+    """ parse of segment data from target.map & target.exe (.rodata/.data/.bss)  """
+    global_value.logger.info("===== parse_segment_info_win begin ===== ")
+    fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.map", "r")
+    p_custom_algo_addr = 0
+    
+    for each_line in fd:
+        if re.match(".text", each_line):
+            s = each_line.strip()  # clear head&tail character ('\n' ' ' '\t' '\r')
+            list_rodata = s.split()  # split ("" " " "\n" "\t")
+            global_value.text_addr = int(list_rodata[1], base=16)  # addr 
+            # self.text_len = int(list_rodata[2], base=16)  # length
+        elif re.search("\s+__data_start__\s+", each_line):
+            s = each_line.strip()  # clear head&tail character ('\n' ' ' '\t' '\r')
+            list_data = s.split()  # split ("" " " "\n" "\t")
+            global_value.data_addr = int(list_data[0], base=16)  # addr
+            # self.data_len = int(list_data[2], base=16)  # length
+        elif re.search("\s+__bss_start__\s+", each_line):
+            s = each_line.strip()  # clear head&tail character ('\n' ' ' '\t' '\r')
+            list_bss = s.split()  # split ("" " " "\n" "\t")
+            global_value.bss_addr = int(list_bss[0], base=16)    # addr
+            # self.bss_len = int(list_bss[2], base=16)    # length
+        elif re.search("\s+__image_base__\s+", each_line):
+            s = each_line.strip()  # clear head&tail character ('\n' ' ' '\t' '\r')
+            list_bss = s.split()  # split ("" " " "\n" "\t")
+            global_value.image_base = int(list_bss[0], base=16)   
+        elif re.search("\s+_nvram_ltable_begin\s+", each_line):
+            s = each_line.strip()  # clear head&tail character ('\n' ' ' '\t' '\r')
+            # l = re.split("\W+", s)
+            list_t = s.split()  # split ("" " " "\n" "\t")
+            table_begin = int(list_t[0], base=16)
+        elif re.search("\s+_nvram_ltable_end\s+", each_line):
+            s = each_line.strip()  # clear head&tail character ('\n' ' ' '\t' '\r')
+            # l = re.split("\W+", s)
+            list_t = s.split()  # split ("" " " "\n" "\t")
+            table_end = int(list_t[0], base=16)
+        elif re.search("\s+nvram_ltable_entry_size\s+", each_line):
+            s = each_line.strip()
+            # l = re.split("\W+", s)
+            list_t = s.split()
+            nvram_ltable_entry_size_addr = int(list_t[0], base=16)
+        elif re.search("\s+NVRAM_EF_ZERO_DEFAULT\s+", each_line):
+            s = each_line.strip()
+            list_t = s.split()
+            const_value.NVRAM_EF_ZERO_DEFAULT = int(list_t[0], base=16)
+        elif re.search("\s+NVRAM_EF_FF_DEFAULT\s+", each_line):
+            s = each_line.strip()
+            list_t = s.split()
+            const_value.NVRAM_EF_FF_DEFAULT = int(list_t[0], base=16)
+        elif re.search("\s+NVRAM_EF_SPECIAL_DEFAULT\s+", each_line):
+            s = each_line.strip()
+            list_t = s.split()
+            const_value.NVRAM_EF_SPECIAL_DEFAULT = int(list_t[0], base=16)
+        elif global_value.macro & const_value.__NV_CHKSUM_ENHANCE__ and re.search("\s+CUSTOM_CHK_ALGO_CONFIG\s+", each_line ):
+            s = each_line.strip()
+            list_t = s.split()
+            p_custom_algo_addr = int(list_t[0], base=16)
+            
+    fd.close()
+    
+    
+    global_value.table_len = table_end - table_begin
+    global_value.logger.info("text_addr = 0x%x", global_value.text_addr)
+    global_value.logger.info("data_addr = 0x%x", global_value.data_addr)
+    global_value.logger.info("bss_addr = 0x%x", global_value.bss_addr)
+    global_value.logger.info("image_base = 0x%x", global_value.image_base)
+    global_value.logger.info("nvram_ltable_entry_size_addr = 0x%x", nvram_ltable_entry_size_addr)
+    global_value.logger.info("table_len = 0x%x", global_value.table_len)
+    
+    # ===
+    # check read .map , show error log
+    if not global_value.text_addr:
+        global_value.logger.debug("text_addr = 0 ,read .text error!")
+        sys.exit(1)
+    if not global_value.data_addr:
+        global_value.logger.debug("data_addr = 0 ,read __data_start__ error!")
+        sys.exit(1)
+    if not global_value.bss_addr:
+        global_value.logger.debug("bss_addr = 0 ,read __bss_start__ error!")  
+        sys.exit(1)
+    if not global_value.image_base:
+        global_value.logger.debug("image_base = 0 ,read __image_base__ error!")  
+        sys.exit(1)    
+    if not table_begin:
+        global_value.logger.debug("table_begin = 0 ,read _nvram_ltable_begin error!")  
+        sys.exit(1)    
+    if not table_end:
+        global_value.logger.debug("table_end = 0 ,read _nvram_ltable_end error!")  
+        sys.exit(1)    
+    if not nvram_ltable_entry_size_addr:
+        global_value.logger.debug("nvram_ltable_entry_size_addr = 0 ,read nvram_ltable_entry_size error!")  
+        sys.exit(1)
+    if not const_value.NVRAM_EF_ZERO_DEFAULT:
+        global_value.logger.debug("NVRAM_EF_ZERO_DEFAULT = 0 ,read NVRAM_EF_ZERO_DEFAULT error!")  
+        sys.exit(1)
+    if not const_value.NVRAM_EF_FF_DEFAULT:
+        global_value.logger.debug("NVRAM_EF_FF_DEFAULT = 0 ,read NVRAM_EF_FF_DEFAULT error!")  
+        sys.exit(1)
+    if not const_value.NVRAM_EF_SPECIAL_DEFAULT:
+        global_value.logger.debug("NVRAM_EF_SPECIAL_DEFAULT = 0 ,read NVRAM_EF_SPECIAL_DEFAULT error!")  
+        sys.exit(1)
+    # ===
+    
+    # fd = open(os.path.join(global_value.path, "nvram_auto_gen", "nvram_auto_gen_target.exe"), "rb")
+    fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.exe", "rb")
+    # read dos header
+    dos_header_len = 0x40
+    r_bin = fd.read(dos_header_len)
+    s = struct.unpack("16I", r_bin)
+    pe_file_header_offset = s[15]
+    # read pe file header
+    fd.seek(pe_file_header_offset)
+    pe_file_header_length = 0x18
+    r_bin = fd.read(pe_file_header_length)
+    s = struct.unpack("5I2H", r_bin)
+    op_header_size = s[5]
+    # read section info
+    section_offset = pe_file_header_offset + pe_file_header_length + op_header_size
+    section_info_length = 0x28
+    fd.seek(section_offset)
+    for i in range(5):
+        r_bin = fd.read(section_info_length)
+        s = struct.unpack("8s6I2HI", r_bin)
+        name = s[0].decode("ascii")[:-1]
+        start = s[2]
+        size = s[3]
+        file_offset = s[4]
+        global_value.logger.info("name = %s, start = %x, size = %x, file_offset = %x",
+                                         name, start, size, file_offset)
+        # if name.count(".text") != 0:
+        if re.match(".text", name):
+            text_offset = start - file_offset
+        # elif name.count(".data") != 0:
+        elif re.match(".data", name):
+            data_offset = start - file_offset
+        # elif name.count(".bss") != 0:
+        elif re.match(".bss", name):
+            bss_offset = start - file_offset
+        # elif name.count(".idata") != 0:
+        elif re.match(".idata", name):
+            pass
+        else:   # ltable
+            ltable_offset = start - file_offset
+    
+    # print("%x %x %x %x" % (text_offset, data_offset, bss_offset, ltable_offset))
+    
+    global_value.text_offset = text_offset
+    global_value.data_offset = data_offset
+    global_value.bss_offset = bss_offset
+    global_value.ltable_offset = ltable_offset
+    global_value.logger.info("text_offset = %x, data_offset = %x, bss_offset = %x, ltable_offset = %x",
+                                         global_value.text_offset, global_value.data_offset,
+                                         global_value.bss_offset, global_value.ltable_offset)
+    # ===
+    if not global_value.text_offset:
+        global_value.logger.debug("text_offset = 0 ,read .exe header error!")  
+        sys.exit(1)
+    if not global_value.data_offset:
+        global_value.logger.debug("data_offset = 0 ,read .exe header error!")  
+        sys.exit(1)    
+    if not global_value.bss_offset:
+        global_value.logger.debug("bss_offset = 0 ,read .exe header error!")  
+        sys.exit(1)
+    if not global_value.ltable_offset:
+        global_value.logger.debug("ltable_offset = 0 ,read .exe header error!")  
+        sys.exit(1)
+    # ===
+                                         
+    global_value.nvram_ltable_entry_length = read_int_in_exe(fd, nvram_ltable_entry_size_addr)
+    global_value.logger.info("nvram_ltable_entry_length = 0x%x", global_value.nvram_ltable_entry_length)
+    
+    
+    # check target 64bit or 32bit
+    fd.seek(const_value.WIN_BIT_ADDR)
+    b = fd.read(1)
+    if type(b) == str: # python 2
+        bit_data = ord(b)
+    else:
+        bit_data = int(b[0])
+    
+    if bit_data == const_value.WIN_64BIT_DATA:  # 64bit
+        global_value.target_bit = const_value.TARGET_64BIT
+        global_value.logger.debug("win target is 64bit! ")
+    elif bit_data == const_value.WIN_32BIT_DATA:  # 32bit
+        global_value.target_bit = const_value.TARGET_32BIT
+        global_value.logger.debug("win target is 32bit! ")
+    else:
+        global_value.logger.debug("check win bit error! bit_data = 0x%x", bit_data)
+        sys.exit(1)
+    
+    
+    
+    fd.close()   
+    
+    if not global_value.nvram_ltable_entry_length:
+        global_value.logger.debug("nvram_ltable_entry_length = 0 ,read .exe info error!")  
+        sys.exit(1)
+    
+    global_value.table_offset = table_begin - global_value.image_base - global_value.ltable_offset
+    global_value.logger.info("table_offset = 0x%x", global_value.table_offset)
+    
+    # ===========
+    # read custom algo config
+    if global_value.macro & const_value.__NV_CHKSUM_ENHANCE__:
+        fd = autogen_open_file(global_value.autogen_path, "nvram_auto_gen_target.exe", "rb")
+        if not p_custom_algo_addr:
+            global_value.logger.debug("read CUSTOM_CHK_ALGO_CONFIG for map error!")
+            sys.exit(1)
+        custom_algo_offset = offset_elf(p_custom_algo_addr)
+        fd.seek(custom_algo_offset)
+        size = struct.calcsize("4I")
+        b = fd.read(size)
+        s = struct.unpack("4I", b)
+        global_value.enhance_size = s[0]
+        global_value.enhance_type = s[1]
+        global_value.default_size = s[2]
+        global_value.default_type = s[3]
+        global_value.logger.info("enhance_type = %s enhance_size = %d", nvram_algo_type[global_value.enhance_type], global_value.enhance_size)
+        global_value.logger.info("default_type = %s default_size = %d", nvram_algo_type[global_value.default_type], global_value.default_size)
+        fd.close()
+    
+    global_value.logger.info("===== parse_segment_info_win end ===== ")
+    
+
+
+
+
+
+
+
+
+
+
+
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/targethelper.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/targethelper.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/src/targethelper.py
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/__init__.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/__init__.py
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/config.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/config.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/config.py
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/encrypt.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/encrypt.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/encrypt.py
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/exceptions.py b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/exceptions.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/autogen/utils/exceptions.py
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/run.py b/mcu/tools/NVRAMStatistic/autogen_v2/run.py
new file mode 100644
index 0000000..26521a1
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/run.py
@@ -0,0 +1,32 @@
+import sys

+import getopt

+from autogen import main

+

+

+if __name__ == '__main__':

+    try:

+        opts, args = getopt.getopt(sys.argv[1:], "tl:p:")

+    except getopt.GetoptError:

+        print("Example of command")

+        print("run autogen_test: run.py -t -p <outPath>")

+        print("run autogen_main: run.py -p <outPath>")

+        sys.exit(2)

+    run = 0

+    for opt, arg in opts:

+        if opt == "-t":

+            run |= 1 << 0

+        elif opt == "-p":

+            run |= 1 << 1

+            out_path = arg

+    if run & 0x3 == 0x3:

+        from tests import test_suite

+        test_suite.main(out_path)

+    elif run & 0x2 == 0x2:

+        main.main(out_path)

+    else:

+        print("Example of command")

+        print("run autogen_test: run.py -t -p <outPath>")

+        print("run autogen_main: run.py -p <outPath>")

+

+

+

diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/startup.py b/mcu/tools/NVRAMStatistic/autogen_v2/startup.py
new file mode 100644
index 0000000..368b245
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/startup.py
@@ -0,0 +1,269 @@
+import os
+import subprocess
+import re
+import sys
+import platform
+from sys import argv
+
+file_out_path = ""
+editor_file_path = [os.path.join("./interface/service/nvram"),os.path.join( "./custom/protocol/common/ps")]
+info_file_path = os.path.join(file_out_path, "bin", "log")
+inc_file_path = os.path.join(file_out_path, "tmp")
+editor_file = []
+def_file = []
+lid_stu_map = {}
+
+def nvram_gen_open_file(file_path, file_name, mode="r"):
+    file_pathname = os.path.join(file_path, file_name)
+    if mode == "r":
+        # file not exist.
+        if not os.access(file_pathname, os.F_OK):   
+            printf("error: %s not exist." % file_pathname)
+            sys.exit(2)
+        # file not read.
+        if not os.access(file_pathname, os.R_OK):
+            printf("error: %s exist, but it cannot be read." % file_pathname)
+            sys.exit(2)
+    elif mode == "w+":
+        # floder not write.
+        if not os.access(file_path, os.F_OK):
+            printf("error: folder no exist: %s" % file_path)
+            sys.exit(2)
+    try:
+        fd = open(file_pathname, mode)
+    except:
+        printf("error: open file error.")
+        printf("file_pathname: %s , mode: %s" % (file_pathname, mode))
+        raise
+    
+    return fd
+
+def printf(strs, file=sys.stdout, end="\n", flush=False):
+    strs_val = strs + end
+    file.write(strs_val)
+    if flush:
+        file.flush()
+
+
+def gen_editor_data_item():
+    """ parse editor file name, create and write nvram_editor_data_item.c """
+    global editor_file
+    """ list containing the names of the entries in the directory given by path. """
+    for editor in editor_file_path:
+        if not os.access(editor, os.F_OK):  
+            printf("error: %s not exist." % editor)
+            sys.exit(2)
+        if not os.access(editor, os.R_OK):
+            printf("error: %s exist, but it cannot be read." % editor)
+            sys.exit(2)
+        dirs = os.listdir(editor)
+        """ check filename, find editor files name saved to list. """
+        editor_pat = re.compile("nvram_editor\.h$")
+        def_pat = re.compile("nvram_def\.h$")
+        for item in dirs:
+            if editor_pat.search(item):
+                editor_file.append(item)
+            if def_pat.search(item):
+                def_file.append(item)
+
+    editor_file.append("nvram_editor_data_item.h")
+    editor_file.sort()
+    """ write include file to file. """
+    fd = nvram_gen_open_file(file_out_path, "nvram_editor_data_item.c", "w+")
+    for item in editor_file:
+        printf("#include \"%s\"" % item, file=fd, flush=True)
+
+    fd.close()
+
+
+def gen_gcc_option():
+    """ parse macro in info.log, save to list, write macro to gcc_option.h """
+    define_data = []
+    """ parse macro in info.log """
+    fd = nvram_gen_open_file(info_file_path, "info.log", "r")
+    for each_line in fd:
+        if each_line.isspace():
+            continue
+        if each_line.count("[ COMMON INCLUDE PATH ]") != 0:
+            break
+        if (each_line.count("[") != 0) or (each_line.count("]") != 0):
+            continue
+        item = each_line.replace("=", " ")
+        item = item.strip()  # remove trailing characters "\n \r \t"
+        define_data.append(item)
+    fd.close()
+    # add compile option for nvram gen 
+    define_data.append("__NVRAM_INTERNAL_LID_DESCRIPTION_ENABLE__")
+    define_data.append("__NV_GEN_FULL_LID__")
+    
+    """ write define macro to file. """
+    fd = nvram_gen_open_file(file_out_path, "gcc_option.h", "w+")
+    printf("#ifndef __GCC_OPTION_H__", file=fd, flush=True)
+    printf("#define __GCC_OPTION_H__", file=fd, flush=True)
+    printf("", file=fd, flush=True)
+
+    for item in define_data:
+        printf("#define %s" % item, file=fd, flush=True)
+
+    printf("", file=fd, flush=True)
+    printf("#endif", file=fd, flush=True)
+    fd.close()
+
+def find_include_path_win(gcc, out_path):
+    """ create gcc preprocessor command and run (win)"""
+    # create gcc preprocess command
+    gcc_command = "\"./" + gcc + "\"" + " -DGEN_FOR_PC -E -imacros gcc_option.h -fno-strict-aliasing -fshort-enums"
+    
+    fd = nvram_gen_open_file(inc_file_path, "~inc.tmp.tmp", "r")
+    for each_line in fd:
+        item = each_line.strip()  # remove trailing characters "\n \r \t"
+        if os.path.exists(item):  # check existing path
+            gcc_command = gcc_command + " -I " + item
+    fd.close()
+    
+    fd_com = nvram_gen_open_file(file_out_path, "gcc_com.mak", "w+")
+    printf("all:", file=fd_com)
+    printf("\t%s" % gcc_command+" "+out_path+"/nvram_auto_gen/nvram_editor_data_item.c"+" -o "+out_path+"/nvram_auto_gen/nvram_editor_data_item.i", file=fd_com)
+    fd_com.close()
+    
+    printf("===============win gcc file build======================")
+    printf("\".\\tools\\MSYS\\bin\\make.exe\" -f "+out_path+"/nvram_auto_gen/gcc_com.mak")
+    p  = subprocess.Popen("\".\\tools\\MSYS\\bin\\make.exe\" -f "+out_path+"/nvram_auto_gen/gcc_com.mak", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    outs, errs = p.communicate()
+    printf("gcc run log:")
+    if p.returncode != 0:   # run fail 
+        printf("gcc run fail! ")
+        printf("exit code = %d" % p.returncode)
+        printf("outs:")
+        printf(str(outs))
+        printf("errs:")
+        printf(str(errs))
+    else:
+        printf("gcc run pass! ")
+        printf("outs:")
+        printf(str(outs))
+
+def find_include_path():
+    """ create gcc preprocessor command and run """
+    # create gcc preprocess command
+    option_path = os.path.join(file_out_path, "gcc_option.h")
+    gcc_command = "gcc -DGEN_FOR_PC -E -C -imacros {} -fno-strict-aliasing -fshort-enums".format(option_path)
+    
+    fd = nvram_gen_open_file(inc_file_path, "~inc.tmp.tmp", "r")
+    for each_line in fd:
+        item = each_line.strip()  # remove trailing characters "\n \r \t"
+        if os.path.exists(item):  # check existing path
+            gcc_command = gcc_command + " -I " + item
+    fd.close()
+    gcc_command = gcc_command + " " + file_out_path + "/nvram_editor_data_item.c" + " -o " + file_out_path + "/nvram_editor_data_item.i"
+    
+    # shell run : gcc preprocess
+    printf("===============linux gcc build======================")
+    # printf("gcc command = %s" % gcc_command)
+    p  = subprocess.Popen(gcc_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    outs, errs = p.communicate()
+    printf("gcc run log:")
+    if p.returncode != 0:   # run fail 
+        printf("gcc run fail! ")
+        printf("exit code = %d" % p.returncode)
+        printf("outs:")
+        printf(outs)
+        printf("errs:")
+        printf(errs)
+    else:
+        printf("gcc run pass! ")
+        printf("outs:")
+        printf(outs)
+
+
+def parse_lid_stu_map():
+    """ parse lid struct name in nvram_editor_data_item.i, save to lid_stu_map dict """
+    global lid_stu_map
+    fd = nvram_gen_open_file(file_out_path, "nvram_editor_data_item.i", "r")
+    strs = fd.read()
+    fd.close()
+
+    """ all non-overlapping matches, return string list """
+    """
+    string format example:
+    LID_BIT "000" NVRAM_EF_STATIC_APPLMN_LID nvram_ef_static_applmn_struct *
+    or
+    LID_BIT MULTIPLE_LID "000" NVRAM_EF_EL1_MPRADJTBL_LID nvrm_el1_mqr_struct *
+    """
+    re_list = re.findall("LID_BIT[\s(MULTIPLE_LID)]*\"[0-9]{3}\"\s*NVRAM_EF_\w*_LID\s*\w*\s*\*", strs)
+
+    for item in re_list:
+        strs = re.sub("LID_BIT[\s(MULTIPLE_LID)]*\"[0-9]{3}\"\s*", "", item, count=1)
+        strs = re.sub("\s*\*", "", strs, count=1)
+        dict = re.split("\s*", strs)
+        lid_stu_map[dict[1]] = dict[0]  # add to dict
+    # for i in lid_stu_map.items():
+    #     printf(i)
+
+
+def gen_lid_stu_file():
+    """ gen nvram_lid_stu_tmp.h file """
+    fd = nvram_gen_open_file(file_out_path, "nvram_lid_stu_tmp.h", "w+")
+
+    printf("#ifndef __NVRAM_LID_STU_TMP_H__", file=fd, flush=True)
+    printf("#define __NVRAM_LID_STU_TMP_H__", file=fd, flush=True)
+    printf("", file=fd, flush=True)
+    printf("#include \"%s\"" % "nvram_group_editor.h" , file=fd, flush=True)
+    printf("#include \"%s\"" % "nvram_group_def.h", file=fd, flush=True)
+    printf("", file=fd, flush=True)
+    printf("/*\n * Variables\n */", file=fd, flush=True)
+    printf("", file=fd, flush=True)
+    for item in lid_stu_map.keys():
+        printf("static ", file=fd, end="", flush=True)
+        printf("%s " % item, file=fd, end="", flush=True)
+        printf("%s" % item + "_var", file=fd, end="", flush=True)
+        printf(" = {0};", file=fd, end="\n", flush=True)
+    printf("", file=fd, flush=True)
+    printf("#endif", file=fd, flush=True)
+
+
+def main(out_path, gcc):
+    global file_out_path
+    global info_file_path
+    global inc_file_path
+    file_out_path = os.path.join(out_path, "nvram_auto_gen")
+    info_file_path = os.path.join(out_path, "bin", "log")
+    inc_file_path = os.path.join(out_path, "tmp")
+    printf("file_out_path = %s" % file_out_path)
+    printf("info_file_path = %s" % info_file_path)
+    printf("inc_file_path = %s" % inc_file_path)
+
+    printf("run gen_editor_data_item()")
+    # gen_editor_data_item()
+    editor_file = os.path.join(file_out_path, "nvram_editor_data_item.c")
+    with open(editor_file, "w") as fd:
+        fd.write('#include "nvram_group_editor.h"')
+    printf("run gen_gcc_option()")
+    gen_gcc_option()
+    printf("run find_include_path()")
+    if platform.system() == "Windows":   # windows
+        find_include_path_win(gcc, out_path)
+    elif platform.system() == "Linux":  # linux              
+        find_include_path()
+    else:
+        printf("platform error: platform is not windows or linux!")
+        printf("platform.system() = %s" % platform.system())
+        sys.exit(1)
+    printf("run parse_lid_stu_map()")
+    parse_lid_stu_map()
+    printf("run gen_lid_stu_file()")
+    gen_lid_stu_file()
+
+
+if __name__ == '__main__':
+    printf("out path = %s" % argv[1])
+    printf("gcc = %s" % argv[2])
+    # printf("platfrom = %s" % argv[3])
+    # if len(argv) != 4:
+    #    printf("command error:")
+    #    printf("Example command: startup.py ./build/MT6885_SP/NLWCTG gcc platfrom" )
+    #else:
+    main(argv[1], argv[2])
+
+        
+        
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/tests/__init__.py b/mcu/tools/NVRAMStatistic/autogen_v2/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/tests/__init__.py
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/tests/lid_table_handle.py b/mcu/tools/NVRAMStatistic/autogen_v2/tests/lid_table_handle.py
new file mode 100644
index 0000000..305f924
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/tests/lid_table_handle.py
@@ -0,0 +1,163 @@
+from autogen.src.initconfig import logical_data_item_table
+from autogen.src.initconfig import const_value
+from autogen.src.initconfig import global_value
+from autogen.src.initconfig import LtableEntry
+import unittest
+
+fd = open("auto_gen_test_report.txt", "w+")
+# creat TestRunner
+runner = unittest.TextTestRunner(verbosity=3, stream=fd)
+
+def get_attr_str(attr):
+    ret_str = ""
+    if attr == const_value.NVRAM_ATTR_AVERAGE:
+        return "NVRAM_ATTR_AVERAGE"
+    if attr & const_value.NVRAM_ATTR_MULTI_DEFAULT:
+        ret_str += " | NVRAM_ATTR_MULTI_DEFAULT"
+    if attr & const_value.NVRAM_ATTR_WRITEPROTECT:
+        ret_str += " | NVRAM_ATTR_WRITEPROTECT"    
+    if attr & const_value.NVRAM_ATTR_MULTIPLE:
+        ret_str += " | NVRAM_ATTR_MULTIPLE"    
+    if attr & const_value.NVRAM_ATTR_CONFIDENTIAL:
+        ret_str += " | NVRAM_ATTR_CONFIDENTIAL"    
+    if attr & const_value.NVRAM_ATTR_MULTIREC_READ:
+        ret_str += " | NVRAM_ATTR_MULTIREC_READ"    
+    if attr & const_value.NVRAM_ATTR_MSP:
+        ret_str += " | NVRAM_ATTR_MSP"    
+    if attr & const_value.NVRAM_ATTR_OTA_RESET:
+        ret_str += " | NVRAM_ATTR_OTA_RESET"    
+    if attr & const_value.NVRAM_ATTR_GEN_DEFAULT:
+        ret_str += " | NVRAM_ATTR_GEN_DEFAULT"    
+    if attr & const_value.NVRAM_ATTR_RING:
+        ret_str += " | NVRAM_ATTR_RING"    
+    if attr & const_value.NVRAM_ATTR_PACKAGE:
+        ret_str += " | NVRAM_ATTR_PACKAGE"    
+    if attr & const_value.NVRAM_ATTR_BACKUP_FAT:
+        ret_str += " | NVRAM_ATTR_BACKUP_FAT"    
+    if attr & const_value.NVRAM_ATTR_BACKUP_RAW:
+        ret_str += " | NVRAM_ATTR_BACKUP_RAW"    
+    if attr & const_value.NVRAM_ATTR_RESERVE_BACKWARD:
+        ret_str += " | NVRAM_ATTR_RESERVE_BACKWARD"
+    if attr & const_value.NVRAM_ATTR_FAULT_ASSERT:
+        ret_str += " | NVRAM_ATTR_FAULT_ASSERT" 
+    if attr & const_value.NVRAM_ATTR_COMMITTED:
+        ret_str += " | NVRAM_ATTR_COMMITTED" 
+    if attr & const_value.NVRAM_ATTR_RAW_DATA:
+        ret_str += " | NVRAM_ATTR_RAW_DATA" 
+    if attr & const_value.NVRAM_ATTR_CHKSUM_INTEGRATE:
+        ret_str += " | NVRAM_ATTR_CHKSUM_INTEGRATE" 
+    if attr & const_value.NVRAM_ATTR_MCF_OTA_ADDITIONAL_NOT_CHECK_VERNO:
+        ret_str += " | NVRAM_ATTR_MCF_OTA_ADDITIONAL_NOT_CHECK_VERNO" 
+    if attr & const_value.NVRAM_ATTR_MCF_OTA_FOR_QUERY:
+        ret_str += " | NVRAM_ATTR_MCF_OTA_FOR_QUERY" 
+    if attr & const_value.NVRAM_ATTR_MCF_OTA_BY_OP:
+        ret_str += " | NVRAM_ATTR_MCF_OTA_BY_OP" 
+    if attr & const_value.NVRAM_ATTR_MCF_OTA:
+        ret_str += " | NVRAM_ATTR_MCF_OTA" 
+    return ret_str
+    
+
+def get_cate_str(cate): 
+    ret_str = ""
+    if cate == const_value.NVRAM_CATEGORY_USER:
+        return "NVRAM_ATTR_AVERAGE"
+    if cate & const_value.NVRAM_CATEGORY_INTERNAL:
+        ret_str += " | NVRAM_CATEGORY_INTERNAL"
+    if cate & const_value.NVRAM_CATEGORY_BACKUP_SDS:
+        ret_str += " | NVRAM_CATEGORY_BACKUP_SDS"
+    if cate & const_value.NVRAM_CATEGORY_OTP:
+        ret_str += " | NVRAM_CATEGORY_OTP"
+    if cate & const_value.NVRAM_CATEGORY_CUSTOM_DISK:
+        ret_str += " | NVRAM_CATEGORY_CUSTOM_DISK"
+    if cate & const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE:
+        ret_str += " | NVRAM_CATEGORY_CUSTOM_SENSITIVE"
+    if cate & const_value.NVRAM_CATEGORY_CUSTPACK:
+        ret_str += " | NVRAM_CATEGORY_CUSTPACK"
+    if cate & const_value.NVRAM_CATEGORY_SECUPACK:
+        ret_str += " | NVRAM_CATEGORY_SECUPACK"
+    if cate & const_value.NVRAM_CATEGORY_FUNC_DEFAULT:
+        ret_str += " | NVRAM_CATEGORY_FUNC_DEFAULT"
+    if cate & const_value.NVRAM_CATEGORY_CALIBRAT:
+        ret_str += " | NVRAM_CATEGORY_CALIBRAT"
+    if cate & const_value.NVRAM_CATEGORY_IMPORTANT:
+        ret_str += " | NVRAM_CATEGORY_IMPORTANT"
+    if cate & const_value.NVRAM_CATEGORY_IMPORTANT_L4:
+        ret_str += " | NVRAM_CATEGORY_IMPORTANT_L4"
+    if cate & const_value.NVRAM_CATEGORY_IMPORTANT_L1:
+        ret_str += " | NVRAM_CATEGORY_IMPORTANT_L1"
+    if cate & const_value.NVRAM_CATEGORY_RESERVED:
+        ret_str += " | NVRAM_CATEGORY_RESERVED"
+    return ret_str
+    
+def lid_table_creat():
+    for i in range(3):
+        one_entry = LtableEntry()
+        logical_data_item_table.append(one_entry)
+    const_value.NVRAM_EF_ZERO_DEFAULT = 0x00
+    const_value.NVRAM_EF_FF_DEFAULT = 0xff
+    const_value.NVRAM_EF_SPECIAL_DEFAULT = 0x55
+    const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM = 128
+    const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SIZE = const_value.NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM * const_value.NVRAM_RECORD_SECTOR_SIZE
+    global_value.path = "."
+
+    logical_data_item_table[0].lid = 2
+    logical_data_item_table[0].str_LID = "NVRAM_EF_UMTS_IMSI_LID"
+    logical_data_item_table[0].category = 0  # set 0
+    logical_data_item_table[0].attr = 0  # set 0
+    logical_data_item_table[0].total_records = 2
+    logical_data_item_table[0].size = 24
+    logical_data_item_table[0].FilePrefix = "UM02"
+    logical_data_item_table[0].FileVerno = "000"
+    logical_data_item_table[0].description = ""
+    logical_data_item_table[0].hash_key = 0xd5bb3d9e
+
+    logical_data_item_table[1].lid = 3
+    logical_data_item_table[1].str_LID = "NVRAM_EF_UMTS_START_HFN_FDD_LID"
+    logical_data_item_table[1].category = 0  # set 0
+    logical_data_item_table[1].attr = 0  # set 0
+    logical_data_item_table[1].total_records = 2
+    logical_data_item_table[1].size = 6
+    logical_data_item_table[1].FilePrefix = "UM03"
+    logical_data_item_table[1].FileVerno = "000"
+    logical_data_item_table[1].description = ""
+    logical_data_item_table[1].hash_key = 0x6a424feb
+
+    logical_data_item_table[2].lid = 4
+    logical_data_item_table[2].str_LID = "NVRAM_EF_UMTS_START_HFN_TDD_LID"
+    logical_data_item_table[2].category = 0  # set 0
+    logical_data_item_table[2].attr = 0  # set 0
+    logical_data_item_table[2].total_records = 2
+    logical_data_item_table[2].size = 6
+    logical_data_item_table[2].FilePrefix = "UM10"
+    logical_data_item_table[2].FileVerno = "000"
+    logical_data_item_table[2].description = ""
+    logical_data_item_table[2].hash_key = 0x3bb47841
+
+
+def data_restore():
+    logical_data_item_table[0].lid = 2
+    logical_data_item_table[0].str_LID = "NVRAM_EF_UMTS_IMSI_LID"
+    logical_data_item_table[0].category = 0  # set 0
+    logical_data_item_table[0].attr = 0  # set 0
+    logical_data_item_table[0].total_records = 2
+    logical_data_item_table[0].size = 24
+    logical_data_item_table[0].FilePrefix = "UM02"
+    logical_data_item_table[0].FileVerno = "000"
+    logical_data_item_table[0].description = ""
+    logical_data_item_table[0].hash_key = 0xd5bb3d9e
+    logical_data_item_table[0].p_default_value = 0x01
+
+    logical_data_item_table[1].lid = 3
+    logical_data_item_table[2].lid = 4
+    global_value.macro = 0
+
+
+def main():
+    lid_table_creat()
+    data_restore()
+
+
+if __name__ == '__main__':
+    print("run begin.")
+    main()
+    print("run end.")
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_attr_conflict.py b/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_attr_conflict.py
new file mode 100644
index 0000000..8d64dd5
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_attr_conflict.py
@@ -0,0 +1,152 @@
+import unittest

+

+from .lid_table_handle import data_restore

+from autogen.src.initconfig import logical_data_item_table

+from autogen.src.initconfig import const_value

+from autogen.src.initconfig import global_value

+from autogen.main import main_test

+

+

+class TestAttributeConflict(unittest.TestCase):

+    def setUp(self):

+        data_restore()

+

+    @classmethod

+    def setUpClass(cls):

+        pass

+

+    @classmethod

+    def tearDownClass(cls):

+        pass

+

+    def test_item_39(self):

+        global_value.macro |= const_value.__NVRAM_PSEUDO_MERGE__

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_PACKAGE

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIPLE

+

+        with self.assertRaisesRegex(SystemExit, "Can't Set NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_MSP for PACKAGE Lid"):

+            main_test()

+        self.assertEqual(logical_data_item_table[0].description, "null")

+

+    def test_item_40(self):

+        global_value.macro |= const_value.__NVRAM_PSEUDO_MERGE__

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_PACKAGE

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MSP

+

+        with self.assertRaisesRegex(SystemExit, "Can't Set NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_MSP for PACKAGE Lid"):

+            main_test()

+        self.assertEqual(logical_data_item_table[0].description, "null")

+

+    def test_item_41(self):

+        logical_data_item_table[0].total_records = 1

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIREC_READ

+

+        with self.assertRaisesRegex(SystemExit,

+                                    "Can't Set the NVRAM_ATTR_MULTIREC_READ or NVRAM_ATTR_MULTI_DEFAULT for the lid "

+                                    "with only one record"):

+            main_test()

+

+    def test_item_42(self):

+        logical_data_item_table[0].total_records = 1

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTI_DEFAULT

+

+        with self.assertRaisesRegex(SystemExit,

+                                    "Can't Set the NVRAM_ATTR_MULTIREC_READ or NVRAM_ATTR_MULTI_DEFAULT for the lid "

+                                    "with only one record"):

+            main_test()

+

+    def test_item_43(self):

+        logical_data_item_table[0].p_default_value = const_value.NVRAM_EF_ZERO_DEFAULT

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_GEN_DEFAULT

+

+        with self.assertRaisesRegex(SystemExit,

+                                    "Can't Set the NVRAM_ATTR_GEN_DEFAULT for the lid with Zero of FF default value"):

+            main_test()

+

+    def test_item_44(self):

+        logical_data_item_table[0].p_default_value = const_value.NVRAM_EF_FF_DEFAULT

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_GEN_DEFAULT

+

+        with self.assertRaisesRegex(SystemExit,

+                                    "Can't Set the NVRAM_ATTR_GEN_DEFAULT for the lid with Zero of FF default value"):

+            main_test()

+

+    def test_item_45(self):

+        logical_data_item_table[0].str_default_value = "NVRAM_EF_ZERO_DEFAULT"

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTI_DEFAULT

+

+        with self.assertRaisesRegex(SystemExit, "Cannot set ZERO_DEFAULT or FF_DEFAULT with multi_default!"):

+            main_test()

+

+    def test_item_46(self):

+        logical_data_item_table[0].str_default_value = "NVRAM_EF_FF_DEFAULT"

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTI_DEFAULT

+

+        with self.assertRaisesRegex(SystemExit,

+                                    "Cannot set ZERO_DEFAULT or FF_DEFAULT with multi_default!"):

+            main_test()

+

+    def test_item_47(self):

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_OTA_RESET

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RESERVE_BACKWARD

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_48(self):

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RAW_DATA

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_PACKAGE

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_49(self):

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RAW_DATA

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIPLE

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_50(self):

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RAW_DATA

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RING

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_51(self):

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RAW_DATA

+        logical_data_item_table[0].total_records = 0

+

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_WRITEPROTECT

+        logical_data_item_table[0].lid = 61200

+        logical_data_item_table[0].str_LID = "NVRAM_EF_IMEI_IMEISV_LID"

+        logical_data_item_table[0].FilePrefix = "LD0B"

+        logical_data_item_table[0].FileVerno = "001"

+        logical_data_item_table[0].hash_key = 0xad4532bb

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_52(self):

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RAW_DATA

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_CONFIDENTIAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_53(self):

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RAW_DATA

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MSP

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_54(self):

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIPLE

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_PACKAGE

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+

diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_cate_attr_conflict.py b/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_cate_attr_conflict.py
new file mode 100644
index 0000000..2b44147
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_cate_attr_conflict.py
@@ -0,0 +1,186 @@
+import unittest

+

+from tests.lid_table_handle import data_restore, runner, get_attr_str, get_cate_str

+from autogen.src.initconfig import logical_data_item_table

+from autogen.src.initconfig import const_value

+from autogen.src.initconfig import global_value

+from autogen.src.buildtimecheck import nvram_gen_check_cate_attr_conflicts

+

+

+macro_default = 0x00

+cate_default = 0x00

+attr_default = 0x00

+

+

+class TestCateAttrConflict(unittest.TestCase):

+    def setUp(self):

+        data_restore()

+

+    @classmethod

+    def setUpClass(cls):

+        pass

+

+    @classmethod

+    def tearDownClass(cls):

+        pass

+        

+    def test_check_cate_attr_conflicts(self):

+        # ====================

+        # check func : nvram_gen_check_cate_attr_conflicts

+        test_case = [

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_CALIBRAT ], 

+            "attr": [const_value.NVRAM_ATTR_MULTIPLE, const_value.NVRAM_ATTR_MSP, const_value.NVRAM_ATTR_RING, const_value.NVRAM_ATTR_OTA_RESET, const_value.NVRAM_ATTR_RESERVE_BACKWARD],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_INTERNAL], 

+            "attr": [const_value.NVRAM_ATTR_PACKAGE],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_SECUPACK ], 

+            "attr": [const_value.NVRAM_ATTR_PACKAGE, const_value.NVRAM_ATTR_RAW_DATA],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_CUSTPACK ], 

+            "attr": [const_value.NVRAM_ATTR_RAW_DATA],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_FUNC_DEFAULT ], 

+            "attr": [const_value.NVRAM_ATTR_RAW_DATA],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_OTP ], 

+            "attr": [const_value.NVRAM_ATTR_GEN_DEFAULT, const_value.NVRAM_ATTR_RESERVE_BACKWARD, const_value.NVRAM_ATTR_RAW_DATA],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+        ]

+        

+        runner.stream.write("\n")

+        for dict_case in test_case:

+            for cate in dict_case["cate"]:

+                data_restore()

+                logical_data_item_table[0].category = cate

+                for attr in dict_case["attr"]:

+                    logical_data_item_table[0].attr = attr

+                    runner.stream.write("\tcate = %s, attr = %s, fun = %s\n" %(get_cate_str(cate), get_attr_str(attr), dict_case["func"]))

+                    with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                        dict_case["func"]()

+                    logical_data_item_table[0].attr &= ~attr

+                        

+    def test_check_cate_conflicts(self):

+        # ====================

+        # check func : nvram_gen_check_cate_attr_conflicts

+        test_case = [

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_FUNC_DEFAULT ], 

+            "cate_conf": [const_value.NVRAM_CATEGORY_CUSTPACK, const_value.NVRAM_CATEGORY_SECUPACK],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_CALIBRAT ], 

+            "cate_conf": [const_value.NVRAM_CATEGORY_INTERNAL, const_value.NVRAM_CATEGORY_BACKUP_SDS, 

+                        const_value.NVRAM_CATEGORY_CUSTOM_DISK, const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE,

+                        const_value.NVRAM_CATEGORY_IMPORTANT, const_value.NVRAM_CATEGORY_OTP,

+                        const_value.NVRAM_CATEGORY_IMPORTANT_L4, const_value.NVRAM_CATEGORY_IMPORTANT_L1,

+                        const_value.NVRAM_CATEGORY_RESERVED],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_IMPORTANT ], 

+            "cate_conf": [const_value.NVRAM_CATEGORY_IMPORTANT_L1, const_value.NVRAM_CATEGORY_IMPORTANT_L4, const_value.NVRAM_CATEGORY_INTERNAL, const_value.NVRAM_CATEGORY_OTP],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_IMPORTANT_L4 ], 

+            "cate_conf": [const_value.NVRAM_CATEGORY_IMPORTANT_L1, const_value.NVRAM_CATEGORY_INTERNAL, const_value.NVRAM_CATEGORY_OTP],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_INTERNAL ], 

+            "cate_conf": [const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE, const_value.NVRAM_CATEGORY_OTP],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE ], 

+            "cate_conf": [const_value.NVRAM_CATEGORY_CUSTPACK, const_value.NVRAM_CATEGORY_SECUPACK, const_value.NVRAM_CATEGORY_OTP],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_CUSTPACK ], 

+            "cate_conf": [const_value.NVRAM_CATEGORY_SECUPACK, const_value.NVRAM_CATEGORY_OTP],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "cate": [const_value.NVRAM_CATEGORY_SECUPACK ], 

+            "cate_conf": [const_value.NVRAM_CATEGORY_OTP],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+        ]

+        

+        runner.stream.write("\n")

+        for dict_case in test_case:

+            for cate in dict_case["cate"]:

+                data_restore()

+                logical_data_item_table[0].category = cate

+                for cate_conf in dict_case["cate_conf"]:

+                    logical_data_item_table[0].category |= cate_conf

+                    runner.stream.write("\tcate = %s, fun = %s\n" %(get_cate_str(logical_data_item_table[0].category), dict_case["func"]))

+                    with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                        dict_case["func"]()

+                    logical_data_item_table[0].category &= ~cate_conf

+    

+    # ====================

+    # check func : nvram_gen_check_cate_attr_conflicts

+    def test_check_attr_conflicts(self):

+        test_case = [

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "attr": [const_value.NVRAM_ATTR_MULTIPLE ], 

+            "attr_conf": [const_value.NVRAM_ATTR_PACKAGE],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "attr": [const_value.NVRAM_ATTR_OTA_RESET ], 

+            "attr_conf": [const_value.NVRAM_ATTR_RESERVE_BACKWARD],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+            {"func": nvram_gen_check_cate_attr_conflicts, 

+            "macro": macro_default,  

+            "attr": [const_value.NVRAM_ATTR_RAW_DATA ], 

+            "attr_conf": [const_value.NVRAM_ATTR_PACKAGE, const_value.NVRAM_ATTR_MULTIPLE, const_value.NVRAM_ATTR_RING, const_value.NVRAM_ATTR_WRITEPROTECT, const_value.NVRAM_ATTR_CONFIDENTIAL, const_value.NVRAM_ATTR_MSP],   

+            "err_str": "Please adjust LID's attributes and/or categories",

+            },

+        ]

+        runner.stream.write("\n")

+        for dict_case in test_case:

+            for attr in dict_case["attr"]:

+                data_restore()

+                logical_data_item_table[0].attr = attr

+                for attr_conf in dict_case["attr_conf"]:

+                    logical_data_item_table[0].attr |= attr_conf

+                    runner.stream.write("\tattr = %s, fun = %s\n" %(get_attr_str(logical_data_item_table[0].attr), dict_case["func"]))

+                    with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                        dict_case["func"]()

+                    logical_data_item_table[0].attr &= ~attr_conf

+    

diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_cate_conflict.py b/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_cate_conflict.py
new file mode 100644
index 0000000..0b35810
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_cate_conflict.py
@@ -0,0 +1,388 @@
+import unittest

+

+from tests.lid_table_handle import data_restore

+from autogen.src.initconfig import logical_data_item_table

+from autogen.src.initconfig import const_value

+from autogen.src.initconfig import global_value

+from autogen.main import main_test

+

+

+class TestCategoryConflict(unittest.TestCase):

+

+    def setUp(self):

+        data_restore()

+

+    @classmethod

+    def setUpClass(cls):

+        pass

+

+    @classmethod

+    def tearDownClass(cls):

+        pass

+

+    def test_item_1(self):

+        global_value.macro |= const_value.__NVRAM_SECURE_DATA_STORAGE__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_BACKUP_SDS

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE

+

+        with self.assertRaisesRegex(SystemExit, "Sds use with wrong category"):

+            main_test()

+

+    def test_item_2(self):

+        global_value.macro |= const_value.__NVRAM_SECURE_DATA_STORAGE__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_BACKUP_SDS

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_OTP

+

+        with self.assertRaisesRegex(SystemExit, "Sds use with wrong category"):

+            main_test()

+

+    def test_item_3(self):

+        global_value.macro |= const_value.__NVRAM_SECURE_DATA_STORAGE__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_BACKUP_SDS

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTOM_DISK

+

+        with self.assertRaisesRegex(SystemExit, "Sds use with wrong category"):

+            main_test()

+

+    def test_item_4(self):

+        global_value.macro |= const_value.__FPGA__

+        global_value.macro |= const_value.__PALLADIUM__

+        global_value.macro |= const_value._SIMULATION

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_GEN_DEFAULT

+        logical_data_item_table[0].category &= ~const_value.NVRAM_CATEGORY_INTERNAL

+

+        self.assertEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_GEN_DEFAULT,

+                         const_value.NVRAM_ATTR_GEN_DEFAULT)

+

+    def test_item_5(self):

+        global_value.macro |= const_value.__NVRAM_SECURE_DATA_STORAGE__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_INTERNAL

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIPLE

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RING

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_PACKAGE

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_BACKUP_FAT

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_BACKUP_RAW

+

+        main_test()

+

+        self.assertEqual(logical_data_item_table[0].category & const_value.NVRAM_CATEGORY_BACKUP_SDS,

+                         const_value.NVRAM_CATEGORY_BACKUP_SDS)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_MULTIPLE,

+                            const_value.NVRAM_ATTR_MULTIPLE)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_RING, const_value.NVRAM_ATTR_RING)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_PACKAGE,

+                            const_value.NVRAM_ATTR_PACKAGE)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_BACKUP_FAT,

+                            const_value.NVRAM_ATTR_BACKUP_FAT)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_BACKUP_RAW,

+                            const_value.NVRAM_ATTR_BACKUP_RAW)

+

+    def test_item_6(self):

+        # global_value.macro |= const_value.__NVRAM_SECURE_DATA_STORAGE__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CALIBRAT

+

+        # logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIPLE

+        # logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_BACKUP_RAW

+        # logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_BACKUP_FAT

+        global_value.macro |= const_value.__LOW_COST_SUPPORT_COMMON__

+        logical_data_item_table[0].p_default_value = 6

+

+        # logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RING

+        # logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_PACKAGE

+

+        main_test()

+

+        self.assertEqual(logical_data_item_table[0].category & const_value.NVRAM_CATEGORY_CALIBRAT,

+                         const_value.NVRAM_CATEGORY_CALIBRAT)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_MULTIPLE,

+                            const_value.NVRAM_ATTR_MULTIPLE)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_RING, const_value.NVRAM_ATTR_RING)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_PACKAGE,

+                            const_value.NVRAM_ATTR_PACKAGE)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_BACKUP_FAT,

+                            const_value.NVRAM_ATTR_BACKUP_FAT)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_BACKUP_RAW,

+                            const_value.NVRAM_ATTR_BACKUP_RAW)

+

+    def test_item_7(self):

+        global_value.macro |= const_value.__NVRAM_SECURE_DATA_STORAGE__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIPLE

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RING

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_PACKAGE

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_BACKUP_FAT

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_BACKUP_RAW

+

+        main_test()

+

+        self.assertEqual(logical_data_item_table[0].category & const_value.NVRAM_CATEGORY_IMPORTANT,

+                         const_value.NVRAM_CATEGORY_IMPORTANT)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_MULTIPLE,

+                            const_value.NVRAM_ATTR_MULTIPLE)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_RING, const_value.NVRAM_ATTR_RING)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_PACKAGE,

+                            const_value.NVRAM_ATTR_PACKAGE)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_BACKUP_FAT,

+                            const_value.NVRAM_ATTR_BACKUP_FAT)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_BACKUP_RAW,

+                            const_value.NVRAM_ATTR_BACKUP_RAW)

+

+    def test_item_8(self):

+        global_value.macro |= const_value.__NVRAM_SECURE_DATA_STORAGE__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L4

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIPLE

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_RING

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_PACKAGE

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_BACKUP_FAT

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_BACKUP_RAW

+

+        main_test()

+

+        self.assertEqual(logical_data_item_table[0].category & const_value.NVRAM_CATEGORY_IMPORTANT_L4,

+                         const_value.NVRAM_CATEGORY_IMPORTANT_L4)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_MULTIPLE,

+                            const_value.NVRAM_ATTR_MULTIPLE)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_RING, const_value.NVRAM_ATTR_RING)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_PACKAGE,

+                            const_value.NVRAM_ATTR_PACKAGE)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_BACKUP_FAT,

+                            const_value.NVRAM_ATTR_BACKUP_FAT)

+        self.assertNotEqual(logical_data_item_table[0].attr & const_value.NVRAM_ATTR_BACKUP_RAW,

+                            const_value.NVRAM_ATTR_BACKUP_RAW)

+

+    def test_item_9(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_FUNC_DEFAULT

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTPACK

+        logical_data_item_table[0].str_default_value = "NVRAM_EF_SPECIAL_DEFAULT"

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_10(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_FUNC_DEFAULT

+

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_SECUPACK

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_CONFIDENTIAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_11(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L1

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_12(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L4

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_13(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_INTERNAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_14(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L4

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L1

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_15(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L4

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_INTERNAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_16(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L1

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_INTERNAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_17(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_INTERNAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_18(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTPACK

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_19(self): #

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_SECUPACK

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_CONFIDENTIAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_20(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTPACK

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_SECUPACK

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_CONFIDENTIAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_21(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_OTP

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CALIBRAT

+        global_value.macro |= const_value.__LOW_COST_SUPPORT_COMMON__

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_22(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_OTP

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_23(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_OTP

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L1

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_24(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_OTP

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L4

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_25(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_OTP

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_INTERNAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_26(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_OTP

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_27(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_OTP

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTPACK

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_28(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_OTP

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_SECUPACK

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_CONFIDENTIAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_29(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTPACK

+        logical_data_item_table[0].str_default_value = "NVRAM_EF_ZERO_DEFAULT"

+

+        with self.assertRaisesRegex(SystemExit, "Cannot set ZERO_DEFAULT or FF_DEFAULT with custpack!"):

+            main_test()

+

+    def test_item_30(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTPACK

+        logical_data_item_table[0].str_default_value = "NVRAM_EF_FF_DEFAULT"

+

+        with self.assertRaisesRegex(SystemExit, "Cannot set ZERO_DEFAULT or FF_DEFAULT with custpack!"):

+            main_test()

+

+    def test_item_31(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CALIBRAT

+        global_value.macro |= const_value.__LOW_COST_SUPPORT_COMMON__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_32(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CALIBRAT

+        global_value.macro |= const_value.__LOW_COST_SUPPORT_COMMON__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L1

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_33(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CALIBRAT

+        global_value.macro |= const_value.__LOW_COST_SUPPORT_COMMON__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L4

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_34(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CALIBRAT

+        global_value.macro |= const_value.__LOW_COST_SUPPORT_COMMON__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_INTERNAL

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_35(self):

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CALIBRAT

+        global_value.macro |= const_value.__LOW_COST_SUPPORT_COMMON__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE

+

+        with self.assertRaisesRegex(SystemExit, "Please adjust LID's attributes and/or categories"):

+            main_test()

+

+    def test_item_36(self):

+        global_value.macro |= const_value.__NVRAM_CUSTOM_SENSITIVE__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT

+

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MSP

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_CONFIDENTIAL

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIPLE

+

+        with self.assertRaisesRegex(SystemExit, "Category internal & calibrat & important & sensitive can't be used at the same time!"):

+            main_test()

+

+    def test_item_37(self):

+        global_value.macro |= const_value.__NVRAM_CUSTOM_SENSITIVE__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L1

+

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MSP

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_CONFIDENTIAL

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIPLE

+

+        with self.assertRaisesRegex(SystemExit, "Category internal & calibrat & important & sensitive can't be used at the same time!"):

+            main_test()

+

+    def test_item_38(self):

+        global_value.macro |= const_value.__NVRAM_CUSTOM_SENSITIVE__

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE

+        logical_data_item_table[0].category |= const_value.NVRAM_CATEGORY_IMPORTANT_L4

+

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MSP

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_CONFIDENTIAL

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_MULTIPLE

+

+        with self.assertRaisesRegex(SystemExit, "Category internal & calibrat & important & sensitive can't be used at the same time!"):

+            main_test()

diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_other.py b/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_other.py
new file mode 100644
index 0000000..268985d
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_other.py
@@ -0,0 +1,547 @@
+import unittest

+

+from tests.lid_table_handle import data_restore, runner, get_attr_str, get_cate_str

+from autogen.src.initconfig import logical_data_item_table

+from autogen.src.initconfig import const_value

+from autogen.src.initconfig import global_value

+

+from autogen.src.gen_assign_entry import adjust_attr_cate_i, adjust_attr_cate_ii, adjust_attr_cate_iii

+from autogen.src.gen_assign_entry import adjust_attr_cate_iv, adjust_attr_cate_v, adjust_attr_cate_vi

+from autogen.src.gen_assign_entry import adjust_attr_cate_vii, adjust_attr_cate_viii, adjust_attr_cate_xi

+from autogen.src.gen_assign_entry import check_item_data_i, check_item_data_ii, check_item_data_iii

+from autogen.src.gen_assign_entry import check_item_data_iv, check_item_data_v, check_item_data_vi

+from autogen.src.buildtimecheck import check_lid_enum_overlapping, check_write_protect

+from autogen.src.buildtimecheck import check_special_lid_parameter, hash_md5, check_lid_hash_key

+from autogen.src.buildtimecheck import check_lid_fileprefix_overlapping

+

+macro_default = 0x00

+cate_default = 0x00

+attr_default = 0x00

+

+

+list_test_item = [

+    # ====================

+    # check func : adjust_attr_cate_ii,

+    {"func": adjust_attr_cate_ii, 

+    "macro": macro_default, 

+    "cate": [const_value.NVRAM_CATEGORY_CALIBRAT], 

+    "attr": [const_value.NVRAM_ATTR_RESERVE_BACKWARD, const_value.NVRAM_ATTR_MULTIPLE],

+    "err_str": "Can't Set NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_RESERVE_BACKWARD for Calibrate Lid",

+    },

+    {"func": adjust_attr_cate_ii, 

+    "macro": const_value.__NVRAM_BACKUP_DISK_FAT__, 

+    "cate": [const_value.NVRAM_CATEGORY_CALIBRAT], 

+    "attr": [const_value.NVRAM_ATTR_BACKUP_RAW],  # const_value.NVRAM_ATTR_MULTIPLE  

+    "err_str": "Can't Set the NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_BACKUP_RAW for Calibrate",

+    },

+    {"func": adjust_attr_cate_ii, 

+    "macro": const_value.__NVRAM_BACKUP_DISK_FAT__, 

+    "cate": [const_value.NVRAM_CATEGORY_CALIBRAT], 

+    "attr": [attr_default],  # no define NVRAM_ATTR_BACKUP_FAT

+    "err_str": "Should set the NVRAM_ATTR_BACKUP_FAT for Calibrate",

+    },

+    {"func": adjust_attr_cate_ii, 

+    "macro": const_value.__NVRAM_BACKUP_DISK_RAW__, 

+    "cate": [const_value.NVRAM_CATEGORY_CALIBRAT], 

+    "attr": [const_value.NVRAM_ATTR_BACKUP_FAT],  # const_value.NVRAM_ATTR_MULTIPLE  

+    "err_str": "Can't Set the NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_BACKUP_FAT for Calibrate",

+    },

+    {"func": adjust_attr_cate_ii, 

+    "macro": const_value.__NVRAM_BACKUP_DISK_RAW__, 

+    "cate": [const_value.NVRAM_CATEGORY_CALIBRAT], 

+    "attr": [attr_default],  # no define NVRAM_ATTR_BACKUP_RAW

+    "err_str": "Should set the NVRAM_ATTR_BACKUP_RAW for Calibrate",

+    },

+    {"func": adjust_attr_cate_ii, 

+    "macro": macro_default,  # no define __LOW_COST_SUPPORT_COMMON__/__CCCIFS_SUPPORT__/__FS_RAMDISK__

+    "cate": [const_value.NVRAM_CATEGORY_CALIBRAT], 

+    "attr": [attr_default],  # no define NVRAM_ATTR_MULTIPLE

+    "err_str": "Should set the NVRAM_ATTR_MULTIPLE for Calibrate under this scenario",

+    },

+    {"func": adjust_attr_cate_ii, 

+    "macro": const_value.__LOW_COST_SUPPORT_COMMON__,  # jump other check

+    "cate": [const_value.NVRAM_CATEGORY_CALIBRAT], 

+    "attr": [const_value.NVRAM_ATTR_BACKUP_RAW, const_value.NVRAM_ATTR_BACKUP_FAT],  

+    "err_str": "Can't Set the NVRAM_ATTR_BACKUP_RAW/NVRAM_ATTR_BACKUP_FAT for Calibrate",

+    },

+    # ====================

+    # check func : adjust_attr_cate_iii,

+    {"func": adjust_attr_cate_iii, 

+    "macro": const_value.__CCCIFS_SUPPORT__,  

+    "cate": [const_value.NVRAM_CATEGORY_IMPORTANT, const_value.NVRAM_CATEGORY_IMPORTANT_L4], 

+    "attr": [const_value.NVRAM_ATTR_RESERVE_BACKWARD],  

+    "err_str": "Can't Set the NVRAM_ATTR_RESERVE_BACKWARD for Important/Important_L4",

+    },

+    {"func": adjust_attr_cate_iii, 

+    "macro": const_value.__CCCIFS_SUPPORT__,  

+    "cate": [const_value.NVRAM_CATEGORY_IMPORTANT, const_value.NVRAM_CATEGORY_IMPORTANT_L4], 

+    "attr": [attr_default],  # no define NVRAM_ATTR_COMMITTED

+    "err_str": "Suggest Set the NVRAM_ATTR_COMMITTED for Important/Important_L4",

+    },

+    # ====================

+    # check func : adjust_attr_cate_iv,

+    {"func": adjust_attr_cate_iv, 

+    "macro": const_value.__NVRAM_OTP__,  

+    "cate": [const_value.NVRAM_CATEGORY_OTP], 

+    "attr": [const_value.NVRAM_ATTR_WRITEPROTECT, const_value.NVRAM_ATTR_MULTIPLE, const_value.NVRAM_ATTR_MSP, const_value.NVRAM_ATTR_OTA_RESET],  

+    "err_str": "Can't Set NVRAM_ATTR_WRITEPROTECT/NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_MSP/NVRAM_ATTR_OTA_RESET for OTP",

+    },

+    # ====================

+    # check func : adjust_attr_cate_vi,

+    {"func": adjust_attr_cate_vi, 

+    "macro": const_value.__NVRAM_OTP__,  

+    "cate": [const_value.NVRAM_CATEGORY_SECUPACK], 

+    "attr": [const_value.NVRAM_ATTR_MSP, attr_default], # not default NVRAM_ATTR_CONFIDENTIAL  

+    "err_str": "Should set the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL",

+    },

+    {"func": adjust_attr_cate_vi, 

+    "macro": const_value.__NVRAM_OTP__ | const_value.__NVRAM_BIND_TO_CHIP_CIPHER__,  

+    "cate": [const_value.NVRAM_CATEGORY_SECUPACK], 

+    "attr": [attr_default, const_value.NVRAM_ATTR_CONFIDENTIAL, const_value.NVRAM_ATTR_MSP], 

+    "err_str": "Should set the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL",

+    },

+    # ====================

+    # check func : adjust_attr_cate_viii

+    {"func": adjust_attr_cate_viii, 

+    "macro": const_value.__NVRAM_CUSTOM_DISK__,  

+    "cate": [const_value.NVRAM_CATEGORY_CUSTOM_DISK], 

+    "attr": [const_value.NVRAM_ATTR_MSP], # not equal NVRAM_ATTR_AVERAGE   

+    "err_str": "Can't set other attribute except NVRAM_ATTR_AVERAGE",

+    },

+    # ====================

+    # check func : check_item_data_i

+    {"func": check_item_data_i, 

+    "macro": const_value.__NVRAM_CUSTOM_SENSITIVE__,  

+    "cate": [const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE|const_value.NVRAM_CATEGORY_CALIBRAT,

+             const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE|const_value.NVRAM_CATEGORY_IMPORTANT,

+             const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE|const_value.NVRAM_CATEGORY_IMPORTANT_L4,

+             const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE|const_value.NVRAM_CATEGORY_IMPORTANT_L1], 

+    "attr": [attr_default],   

+    "err_str": "Category internal & calibrat & important & sensitive can't be used at the same time!",

+    },

+    {"func": check_item_data_i, 

+    "macro": const_value.__NVRAM_CUSTOM_DISK__,  

+    "cate": [const_value.NVRAM_CATEGORY_CUSTOM_DISK|const_value.NVRAM_CATEGORY_INTERNAL,

+             const_value.NVRAM_CATEGORY_CUSTOM_DISK|const_value.NVRAM_CATEGORY_CALIBRAT,

+             const_value.NVRAM_CATEGORY_CUSTOM_DISK|const_value.NVRAM_CATEGORY_IMPORTANT,

+             const_value.NVRAM_CATEGORY_CUSTOM_DISK|const_value.NVRAM_CATEGORY_IMPORTANT_L4,

+             const_value.NVRAM_CATEGORY_CUSTOM_DISK|const_value.NVRAM_CATEGORY_IMPORTANT_L1], 

+    "attr": [attr_default],    

+    "err_str": "Category internal & calibrat & important & sensitive can't be used at the same time!",

+    },

+    {"func": check_item_data_i, 

+    "macro": const_value.__NVRAM_CUSTOM_DISK__ | const_value.__NVRAM_CUSTOM_SENSITIVE__,  

+    "cate": [const_value.NVRAM_CATEGORY_CUSTOM_DISK|const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE], 

+    "attr": [attr_default],   

+    "err_str": "Category internal & calibrat & important & sensitive can't be used at the same time!",

+    },

+    # ====================

+    # check func : check_item_data_ii

+    {"func": check_item_data_ii, 

+    "macro": const_value.__NVRAM_SECURE_DATA_STORAGE__,  

+    "cate": [const_value.NVRAM_CATEGORY_BACKUP_SDS|const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE,

+             const_value.NVRAM_CATEGORY_BACKUP_SDS|const_value.NVRAM_CATEGORY_CUSTOM_DISK,

+             const_value.NVRAM_CATEGORY_BACKUP_SDS|const_value.NVRAM_CATEGORY_OTP], 

+    "attr": [attr_default],    

+    "err_str": "Sds use with wrong category",

+    },

+    {"func": check_item_data_ii, 

+    "macro": const_value.__NVRAM_SECURE_DATA_STORAGE__,  

+    "cate": [const_value.NVRAM_CATEGORY_BACKUP_SDS], 

+    "attr": [const_value.NVRAM_ATTR_MULTIPLE, const_value.NVRAM_ATTR_RING, const_value.NVRAM_ATTR_PACKAGE, const_value.NVRAM_ATTR_BACKUP_FAT, const_value.NVRAM_ATTR_BACKUP_RAW],   

+    "err_str": "Sds use with wrong attribute LID",

+    },

+    # check func : check_item_data_vi

+    {"func": check_item_data_vi, 

+    "macro": macro_default,  

+    "cate": [const_value.NVRAM_CATEGORY_CALIBRAT], 

+    "attr": [const_value.NVRAM_ATTR_OTA_RESET],   

+    "err_str": "CALIBRAT LID should not have NVRAM_ATTR_OTA_RESET attribute!",

+    },

+    

+]

+

+

+

+class TestOther(unittest.TestCase):

+    def setUp(self):

+        data_restore()

+

+    @classmethod

+    def setUpClass(cls):

+        pass

+

+    @classmethod

+    def tearDownClass(cls):

+        pass

+            

+    

+    def test_common(self):

+        runner.stream.write("\n")

+        for dict_case in list_test_item:

+            data_restore()

+            global_value.macro = dict_case["macro"]

+            for cate in dict_case["cate"]:

+                logical_data_item_table[0].category = cate

+                for attr in dict_case["attr"]:

+                    logical_data_item_table[0].attr = attr

+                    runner.stream.write("\tcate = %s, attr = %s, fun = %s\n" %(get_cate_str(cate), get_attr_str(attr), dict_case["func"]))

+                    with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                        dict_case["func"](logical_data_item_table[0])

+    

+    # ------------------------------------

+    # test func: adjust_attr_cate_i

+    def test_only_one_record(self):

+        dict_case = {

+            "func": adjust_attr_cate_i, 

+            "macro": macro_default,  

+            "attr": [const_value.NVRAM_ATTR_MULTIREC_READ, const_value.NVRAM_ATTR_MULTI_DEFAULT],  

+            "err_str": "Can't Set the NVRAM_ATTR_MULTIREC_READ or NVRAM_ATTR_MULTI_DEFAULT for the lid with only one record",

+            "total_records": 1

+            }

+        runner.stream.write("\n")

+        logical_data_item_table[0].total_records = dict_case["total_records"]

+        for attr in dict_case["attr"]:

+            logical_data_item_table[0].attr = attr

+            runner.stream.write("\tattr = %s, total_records = %d fun = %s\n" %(get_attr_str(attr), dict_case["total_records"], dict_case["func"]))

+            with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                    dict_case["func"](logical_data_item_table[0])

+    # ------------------------------------

+    # test func: adjust_attr_cate_i

+    def test_default_value(self):

+        test_case = [

+            # ====================

+            # check func : adjust_attr_cate_i

+            {"func": adjust_attr_cate_i, 

+            "macro": macro_default,  

+            "attr": const_value.NVRAM_ATTR_GEN_DEFAULT,  

+            "err_str": "Can't Set the NVRAM_ATTR_GEN_DEFAULT for the lid with Zero of FF default value",

+            "p_def_val": [const_value.NVRAM_EF_FF_DEFAULT, const_value.NVRAM_EF_ZERO_DEFAULT],

+            "lid": [const_value.NVRAM_EF_NVRAM_UNIT_TEST_LID-1, const_value.NVRAM_EF_NVRAM_UNIT_TEST_LID_END+1]

+            },

+            {"func": adjust_attr_cate_i, 

+            "macro": const_value.__NVRAM_UT_TEST__,  

+            "attr": const_value.NVRAM_ATTR_GEN_DEFAULT,  

+            "err_str": "Can't Set the NVRAM_ATTR_GEN_DEFAULT for the lid with Zero of FF default value",

+            "p_def_val": [const_value.NVRAM_EF_FF_DEFAULT, const_value.NVRAM_EF_ZERO_DEFAULT],

+            "lid": [const_value.NVRAM_EF_NVRAM_UNIT_TEST_LID-1, const_value.NVRAM_EF_NVRAM_UNIT_TEST_LID_END+1]

+            },

+        ]

+        runner.stream.write("\n")

+        for dict_case in test_case:

+            global_value.macro = dict_case["macro"]

+            logical_data_item_table[0].attr = dict_case["attr"]

+            for lid in dict_case["lid"]:

+                logical_data_item_table[0].lid = lid

+                for p_def_val in dict_case["p_def_val"]:

+                    logical_data_item_table[0].p_default_value = p_def_val

+                    

+                    # --

+                    if lid == const_value.NVRAM_EF_NVRAM_UNIT_TEST_LID-1:

+                        runner.stream.write("\tattr = %s, p_def_val = 0x%x lid = %s fun = %s\n" %(get_attr_str(logical_data_item_table[0].attr), p_def_val, "NVRAM_EF_NVRAM_UNIT_TEST_LID - 1", dict_case["func"]))

+                    else:

+                        runner.stream.write("\tattr = %s, p_def_val = 0x%x lid = %s fun = %s\n" %(get_attr_str(logical_data_item_table[0].attr), p_def_val, "NVRAM_EF_NVRAM_UNIT_TEST_LID_END + 1", dict_case["func"]))

+                    # --

+                    

+                    with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                        dict_case["func"](logical_data_item_table[0])

+                    

+    # ------------------------------------

+    # test func: adjust_attr_cate_v

+    def test_attr_package_set(self):

+        test_case = [

+            # ====================

+            # check func : adjust_attr_cate_v

+            {"func": adjust_attr_cate_v, 

+            "macro": const_value.__NVRAM_PSEUDO_MERGE__,  

+            "attr": attr_default ,  # not define NVRAM_ATTR_PACKAGE

+            "cate": cate_default,   # not define NVRAM_CATEGORY_INTERNAL|NVRAM_CATEGORY_SECUPACK|NVRAM_CATEGORY_IMPORTANT|NVRAM_CATEGORY_CALIBRAT

+            "err_str": "Should set the NVRAM_ATTR_PACKAGE for this lid",

+            "file_size": 0 # (size+checksum)*total < NVRAM_CLUSTER_SIZE

+            },

+            {"func": adjust_attr_cate_v, 

+            "macro": const_value.__NVRAM_PSEUDO_MERGE__ | const_value.__NVRAM_CUSTOM_SENSITIVE__,  

+            "attr": attr_default ,  # not define NVRAM_ATTR_PACKAGE

+            "cate": cate_default,   # not define NVRAM_CATEGORY_INTERNAL|NVRAM_CATEGORY_SECUPACK|NVRAM_CATEGORY_IMPORTANT|NVRAM_CATEGORY_CALIBRAT|NVRAM_CATEGORY_CUSTOM_SENSITIVE

+            "err_str": "Should set the NVRAM_ATTR_PACKAGE for this lid",

+            "file_size": 0 # (size+checksum)*total < NVRAM_CLUSTER_SIZE

+            },

+            {"func": adjust_attr_cate_v, 

+            "macro": const_value.__NVRAM_PSEUDO_MERGE__ | const_value.__NVRAM_CUSTOM_DISK__,  

+            "attr": attr_default ,  # not define NVRAM_ATTR_PACKAGE

+            "cate": cate_default,   # not define NVRAM_CATEGORY_INTERNAL|NVRAM_CATEGORY_SECUPACK|NVRAM_CATEGORY_IMPORTANT|NVRAM_CATEGORY_CALIBRAT|NVRAM_CATEGORY_CUSTOM_DISK

+            "err_str": "Should set the NVRAM_ATTR_PACKAGE for this lid",

+            "file_size": 0 # (size+checksum)*total < NVRAM_CLUSTER_SIZE

+            },

+            {"func": adjust_attr_cate_v, 

+            "macro": const_value.__NVRAM_PSEUDO_MERGE__ | const_value.__NVRAM_CUSTOM_DISK__ | const_value.__NVRAM_CUSTOM_SENSITIVE__,  

+            "attr": attr_default ,  # not define NVRAM_ATTR_PACKAGE

+            "cate": cate_default,   # not define NVRAM_CATEGORY_INTERNAL|NVRAM_CATEGORY_SECUPACK|NVRAM_CATEGORY_IMPORTANT|NVRAM_CATEGORY_CALIBRAT|NVRAM_CATEGORY_CUSTOM_SENSITIVE|NVRAM_CATEGORY_CUSTOM_DISK

+            "err_str": "Should set the NVRAM_ATTR_PACKAGE for this lid",

+            "file_size": 0 # (size+checksum)*total < NVRAM_CLUSTER_SIZE

+            },

+        ]

+        

+        for dict_case in test_case:

+            global_value.macro = dict_case["macro"]

+            with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                dict_case["func"](logical_data_item_table[0])

+                

+    # ------------------------------------

+    # test func: adjust_attr_cate_v

+    def test_attr_package_conf(self):

+        dict_case = {

+            "func": adjust_attr_cate_v, 

+            "macro": const_value.__NVRAM_PSEUDO_MERGE__,  

+            "attr": const_value.NVRAM_ATTR_PACKAGE ,  

+            "attr_conf": [const_value.NVRAM_ATTR_MULTIPLE, const_value.NVRAM_ATTR_MSP],

+            "err_str": "Can't Set NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_MSP for PACKAGE Lid",

+            "desc": "test"

+            }

+        

+        

+        runner.stream.write("\n")

+        global_value.macro = dict_case["macro"]

+        logical_data_item_table[0].attr = dict_case["attr"]

+        for attr_conf in dict_case["attr_conf"]:

+            logical_data_item_table[0].attr |= attr_conf

+            logical_data_item_table[0].description = dict_case["desc"]

+            runner.stream.write("\tattr = %s desc = %s func = %s\n" %(get_attr_str(logical_data_item_table[0].attr), dict_case["desc"], dict_case["func"]))

+            with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                dict_case["func"](logical_data_item_table[0])

+            self.assertEqual(logical_data_item_table[0].description, "null")

+            logical_data_item_table[0].attr &= ~attr_conf   

+    

+    # ------------------------------------

+    # test func: adjust_attr_cate_vii

+    def test_custom_sensitive(self):

+        dict_case = {

+            "func": adjust_attr_cate_vii, 

+            "macro": const_value.__NVRAM_CUSTOM_SENSITIVE__,

+            "cate": const_value.NVRAM_CATEGORY_CUSTOM_SENSITIVE,

+            "attr": [const_value.NVRAM_ATTR_MSP|const_value.NVRAM_ATTR_CONFIDENTIAL, const_value.NVRAM_ATTR_MSP|const_value.NVRAM_ATTR_MULTIPLE, const_value.NVRAM_ATTR_CONFIDENTIAL|const_value.NVRAM_ATTR_MULTIPLE] ,  

+            "err_str": "Should set the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL/NVRAM_ATTR_MULTIPLE",

+            }

+        

+        runner.stream.write("\n")

+        global_value.macro = dict_case["macro"]

+        logical_data_item_table[0].category = dict_case["cate"]

+        for attr in dict_case["attr"]:

+            logical_data_item_table[0].attr = attr

+            runner.stream.write("\tattr = %s cate = %s func = %s\n" %(get_attr_str(attr), get_cate_str(dict_case["cate"]), dict_case["func"]))

+            with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                dict_case["func"](logical_data_item_table[0])

+    # ------------------------------------

+    # test func: adjust_attr_cate_vii

+    def test_internal_and_gen_default(self):

+        dict_case = {

+            "func": adjust_attr_cate_vii, 

+            "macro": [const_value._SIMULATION, const_value.__PALLADIUM__, const_value.__FPGA__],

+            "cate": cate_default,   # not define NVRAM_CATEGORY_INTERNAL

+            "attr": const_value.NVRAM_ATTR_GEN_DEFAULT ,  

+            }

+            

+        for macro in dict_case["macro"]:

+            global_value.macro = macro

+            logical_data_item_table[0].attr = dict_case["attr"]

+            dict_case["func"](logical_data_item_table[0])

+            self.assertNotEqual(logical_data_item_table[0].attr&const_value.NVRAM_ATTR_GEN_DEFAULT, const_value.NVRAM_ATTR_GEN_DEFAULT)

+    

+    # ------------------------------------

+    # test func: adjust_attr_cate_xi

+    def test_cate_file_location(self):

+        dict_case = {

+            "func": adjust_attr_cate_xi, 

+            "macro": const_value.__NVRAM_SECURE_DATA_STORAGE__,

+            "cate": [const_value.NVRAM_CATEGORY_INTERNAL, const_value.NVRAM_CATEGORY_CALIBRAT, const_value.NVRAM_CATEGORY_IMPORTANT, const_value.NVRAM_CATEGORY_IMPORTANT_L4],   

+            "attr": const_value.NVRAM_ATTR_MULTIPLE|const_value.NVRAM_ATTR_RING|const_value.NVRAM_ATTR_PACKAGE|const_value.NVRAM_ATTR_BACKUP_FAT|const_value.NVRAM_ATTR_BACKUP_RAW ,  

+            }

+        

+        runner.stream.write("\n")

+        global_value.macro = dict_case["macro"]

+        for cate in dict_case["cate"]:

+            logical_data_item_table[0].category = cate

+            logical_data_item_table[0].attr = dict_case["attr"]

+            runner.stream.write("\tattr = %s cate = %s func = %s\n" %(get_attr_str(dict_case["attr"]), get_cate_str(cate), dict_case["func"]))

+            dict_case["func"](logical_data_item_table[0])

+            self.assertEqual(logical_data_item_table[0].category&const_value.NVRAM_CATEGORY_BACKUP_SDS, const_value.NVRAM_CATEGORY_BACKUP_SDS)

+            self.assertNotEqual(logical_data_item_table[0].attr&const_value.NVRAM_ATTR_MULTIPLE, const_value.NVRAM_ATTR_MULTIPLE)

+            self.assertNotEqual(logical_data_item_table[0].attr&const_value.NVRAM_ATTR_RING, const_value.NVRAM_ATTR_RING)

+            self.assertNotEqual(logical_data_item_table[0].attr&const_value.NVRAM_ATTR_PACKAGE, const_value.NVRAM_ATTR_PACKAGE)

+            self.assertNotEqual(logical_data_item_table[0].attr&const_value.NVRAM_ATTR_BACKUP_FAT, const_value.NVRAM_ATTR_BACKUP_FAT)

+            self.assertNotEqual(logical_data_item_table[0].attr&const_value.NVRAM_ATTR_BACKUP_RAW, const_value.NVRAM_ATTR_BACKUP_RAW)

+    

+    # ------------------------------------

+    # test func: check_item_data_ii

+    def test_data_put_sds(self):

+        list_case = [

+            {"func": check_item_data_ii, 

+            "macro": const_value.__NVRAM_SECURE_DATA_STORAGE__,

+            "cate": const_value.NVRAM_CATEGORY_BACKUP_SDS,  

+            "attr": attr_default,

+            "size": 129,

+            "total_records": 512,

+            "err_str": "Data is too large to put into sds"

+            },

+            {"func": check_item_data_ii, 

+            "macro": const_value.__NVRAM_SECURE_DATA_STORAGE__ | const_value.__NVRAM_BIND_TO_CHIP_CIPHER__,

+            "cate": const_value.NVRAM_CATEGORY_BACKUP_SDS, 

+            "attr": const_value.NVRAM_ATTR_MSP,            

+            "size": 129,

+            "total_records": 512,

+            "err_str": "Data is too large to put into sds"

+            },

+        ]

+        

+        for dict_case in list_case:

+            global_value.macro = dict_case["macro"]

+            logical_data_item_table[0].attr = dict_case["attr"]

+            logical_data_item_table[0].category = dict_case["cate"]

+            logical_data_item_table[0].size = dict_case["size"]

+            logical_data_item_table[0].total_records = dict_case["total_records"]

+            with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                dict_case["func"](logical_data_item_table[0])

+

+    # ------------------------------------

+    # test func: check_item_data_iii

+    def test_attr_multi_default(self):

+        dict_case = {

+            "func": check_item_data_iii, 

+            "str_def_val": ["NVRAM_EF_ZERO_DEFAULT", "NVRAM_EF_FF_DEFAULT"],

+            "attr": const_value.NVRAM_ATTR_MULTI_DEFAULT,  

+            "err_str": "Cannot set ZERO_DEFAULT or FF_DEFAULT with multi_default!",

+            }

+            

+        runner.stream.write("\n")

+        logical_data_item_table[0].attr = dict_case["attr"]

+        for s_def_val in dict_case["str_def_val"]:

+            logical_data_item_table[0].str_default_value = s_def_val

+            runner.stream.write("\tattr = %s str_def_val = %s func = %s\n" %(get_attr_str(dict_case["attr"]), s_def_val, dict_case["func"]))

+            with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                dict_case["func"](logical_data_item_table[0])

+    

+    # ------------------------------------

+    # test func: check_item_data_iv

+    def test_size_big(self):

+        global_value.macro = macro_default # not define __NVRAM_LARGE_RECORD_SIZE__

+        logical_data_item_table[0].total_records = 512

+        logical_data_item_table[0].size = 128 * 512

+        

+        with self.assertRaisesRegex(SystemExit, "LID Size is too big"):

+            check_item_data_iv(logical_data_item_table[0])

+           

+    # ------------------------------------

+    # test func: check_item_data_iv

+    def test_size_bit_msp(self):

+        global_value.macro = const_value.__NVRAM_BIND_TO_CHIP_CIPHER__ # not define __NVRAM_LARGE_RECORD_SIZE__

+        logical_data_item_table[0].attr = const_value.NVRAM_ATTR_MSP

+        logical_data_item_table[0].total_records = 512

+        logical_data_item_table[0].size = 128 * 512

+        with self.assertRaisesRegex(SystemExit, "LID Size is too big"):

+            check_item_data_iv(logical_data_item_table[0])

+    

+    # ------------------------------------

+    # test func: check_item_data_v

+    def test_cate_custpack(self):

+        dict_case = {

+            "func": check_item_data_v, 

+            "str_def_val": ["NVRAM_EF_ZERO_DEFAULT", "NVRAM_EF_FF_DEFAULT"],

+            "cate": const_value.NVRAM_CATEGORY_CUSTPACK,   

+            "err_str": "Cannot set ZERO_DEFAULT or FF_DEFAULT with custpack!",

+            }

+            

+        runner.stream.write("\n")

+        logical_data_item_table[0].category = dict_case["cate"]

+        for s_def_val in dict_case["str_def_val"]:

+            logical_data_item_table[0].str_default_value = s_def_val

+            runner.stream.write("\tcate = %s str_def_val = %s func = %s\n" %(get_cate_str(dict_case["cate"]), s_def_val, dict_case["func"]))

+            with self.assertRaisesRegex(SystemExit, dict_case["err_str"]):

+                dict_case["func"](logical_data_item_table[0])

+    # ------------------------------------

+    # test func: check_lid_enum_overlapping

+    def test_lid_overlapping(self):

+        logical_data_item_table[1].lid = logical_data_item_table[0].lid

+

+        with self.assertRaisesRegex(SystemExit, "Please contact NVRAM owner if your NVRAM sub-group size should be enlarged"):

+            check_lid_enum_overlapping()

+    # ------------------------------------

+    # test func: check_lid_fileprefix_overlapping

+    def test_prefix_overlapping(self):

+        logical_data_item_table[1].FilePrefix = logical_data_item_table[0].FilePrefix

+        

+        with self.assertRaisesRegex(SystemExit, "duplicated fileprefix and fileverno!"):

+            check_lid_fileprefix_overlapping()

+    # ------------------------------------

+    # test func: check_write_protect

+    def test_write_protect(self):

+        logical_data_item_table[0].attr |= const_value.NVRAM_ATTR_WRITEPROTECT

+        logical_data_item_table[0].str_LID = "NVRAM_EF_IMEI_IMEISV_LID_1"   #

+        with self.assertRaisesRegex(SystemExit, "Please contact NVRAM owner if your really need this attribute for the LID"):

+            check_write_protect()

+    

+    # ------------------------------------

+    # test func: check_special_lid_parameter

+    def test_attr_raw_data(self):

+        logical_data_item_table[0].attr = const_value.NVRAM_ATTR_RAW_DATA

+        logical_data_item_table[0].total_records = 2

+        with self.assertRaisesRegex(SystemExit, "NVRAM_ATTR_RAW_DATA can not support multiple record ,and can only use NVRAM_EF_ZERO_DEFAULT."):

+            check_special_lid_parameter()

+    # ------------------------------------

+    # test func: check_special_lid_parameter

+    def test_attr_raw_data(self):

+        logical_data_item_table[0].attr = const_value.NVRAM_ATTR_RAW_DATA

+        logical_data_item_table[0].total_records = 1

+        logical_data_item_table[0].p_default_value = const_value.NVRAM_EF_FF_DEFAULT # not equal NVRAM_EF_ZERO_DEFAULT

+        with self.assertRaisesRegex(SystemExit, "NVRAM_ATTR_RAW_DATA can not support multiple record ,and can only use NVRAM_EF_ZERO_DEFAULT."):

+            check_special_lid_parameter()

+        

+    # ------------------------------------

+    # test func: hash_md5

+    def test_md5(self):

+        strs = "abcde12345"

+        md5 = list("df6f58808ebfd3e609c234cf2283a989")

+        md5_list = []

+        for i in range(16):

+            md5_list.append(int(md5[2 * i], 16) * 16 + int(md5[2 * i + 1], 16))

+

+        self.assertEqual(md5_list, hash_md5(strs))

+    

+    # ------------------------------------

+    # test func: check_lid_hash_key

+    def test_hash_modify_lid(self):

+        global_value.macro |= const_value.__NVRAM_LID_HASH_CHECK__

+        global_value.macro |= const_value.__MTK_INTERNAL__

+        logical_data_item_table[0].lid = 30

+        with self.assertRaisesRegex(SystemExit, "HASH key check error"):

+            check_lid_hash_key()

+    def test_hash_modify_str(self):

+        global_value.macro |= const_value.__NVRAM_LID_HASH_CHECK__

+        global_value.macro |= const_value.__MTK_INTERNAL__

+        logical_data_item_table[0].str_LID = "NVRAM_EF_IMEI_IMEISV_LID_1"

+

+        with self.assertRaisesRegex(SystemExit, "HASH key check error"):

+            check_lid_hash_key()

+    def test_hash_modify_prefix(self):

+        global_value.macro |= const_value.__NVRAM_LID_HASH_CHECK__

+        global_value.macro |= const_value.__MTK_INTERNAL__

+        l_prefix = list(logical_data_item_table[0].FilePrefix)

+        l_prefix[1] = chr(ord(l_prefix[2]) + 1)

+        logical_data_item_table[0].FilePrefix = "".join(l_prefix)

+        with self.assertRaisesRegex(SystemExit, "HASH key check error"):

+            check_lid_hash_key()

+    def test_hash_modify_verno(self):

+        global_value.macro |= const_value.__NVRAM_LID_HASH_CHECK__

+        global_value.macro |= const_value.__MTK_INTERNAL__

+        l_prefix = list(logical_data_item_table[0].FileVerno)

+        l_prefix[1] = chr(ord(l_prefix[0]) + 1)

+        logical_data_item_table[0].FileVerno = "".join(l_prefix)

+

+        with self.assertRaisesRegex(SystemExit, "HASH key check error"):

+            check_lid_hash_key()

+    def test_hash_modify_hashkey(self):

+        global_value.macro |= const_value.__NVRAM_LID_HASH_CHECK__

+        global_value.macro |= const_value.__MTK_INTERNAL__

+        logical_data_item_table[0].hash_key += 1

+

+        with self.assertRaisesRegex(SystemExit, "HASH key check error"):

+            check_lid_hash_key()
\ No newline at end of file
diff --git a/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_suite.py b/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_suite.py
new file mode 100644
index 0000000..ea8011f
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/autogen_v2/tests/test_suite.py
@@ -0,0 +1,43 @@
+import unittest

+

+from tests.lid_table_handle import lid_table_creat, data_restore, runner

+from tests.test_cate_attr_conflict import TestCateAttrConflict

+from tests.test_other import TestOther

+from autogen.src.initconfig import logical_data_item_table

+from autogen.src.initconfig import const_value

+from autogen.src.initconfig import global_value

+from autogen.src.initconfig import LtableEntry

+

+test_cases = (TestOther, TestCateAttrConflict)

+

+

+def main(logging_path):

+    global_value.logging_path = logging_path

+    global_value.logger_config()

+    lid_table_creat()

+    data_restore()

+    

+    suite = unittest.TestSuite()

+

+    # creat TestLoader , load test case

+    loader = unittest.TestLoader()

+    for test_class in test_cases:

+        # loading test cases in a class

+        tests = loader.loadTestsFromTestCase(test_class)

+        # add test case

+        suite.addTests(tests)

+

+    # creat TestRunner

+    # runner = unittest.TextTestRunner(verbosity=3)

+    # fd.close()

+    

+    # test run

+    runner.run(suite)

+    

+    # with open("auto_gen_test_report.txt", "w+") as f:

+    #     # creat TestRunner

+    #     runner = unittest.TextTestRunner(verbosity=3, stream=f)

+    #     runner.stream.write(strs)

+    #     

+    #     # test run

+    #     runner.run(suite)