rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | import operator |
| 2 | import sys |
| 3 | import os |
| 4 | import platform |
| 5 | |
| 6 | from .src.initconfig import logical_data_item_table |
| 7 | from .src.initconfig import const_value |
| 8 | from .src.initconfig import global_value |
| 9 | from .src.initconfig import LtableEntry |
| 10 | from .src.initconfig import printf |
| 11 | from .src import tableconstructor |
| 12 | from .src import sys_cache_generator |
| 13 | from .src import gen_cache_info |
| 14 | from .src import gen_cat_file |
| 15 | from .src import gen_lid_information |
| 16 | from .src import gen_statistic |
| 17 | from .src import mcf_ota_helper |
| 18 | from .src import custpackhelper |
| 19 | from .src import secupackhelper |
| 20 | from .src import buildtimecheck |
| 21 | from .src import tableconstructor_win |
| 22 | |
| 23 | from .src import gen_assign_entry |
| 24 | |
| 25 | |
| 26 | def main(path): |
| 27 | """ |
| 28 | args: |
| 29 | path: gen file output path, path + "nvram_auto_gen" + filename |
| 30 | """ |
| 31 | # set path |
| 32 | global_value.logging_path = path |
| 33 | global_value.path = path |
| 34 | global_value.autogen_path = os.path.join(global_value.path, "nvram_auto_gen") |
| 35 | global_value.log_path = os.path.join(global_value.path, "bin", "log") |
| 36 | |
| 37 | # check path exist |
| 38 | if not os.access(global_value.autogen_path, os.F_OK): |
| 39 | printf("error: folder no exist: %s" % global_value.autogen_path) |
| 40 | sys.exit(2) |
| 41 | if not os.access(global_value.log_path, os.F_OK): |
| 42 | printf("error: folder no exist: %s" % global_value.log_path) |
| 43 | sys.exit(2) |
| 44 | |
| 45 | global_value.logger_config() |
| 46 | global_value.logger.info("========main========") |
| 47 | # set platform |
| 48 | global_value.platform = platform.system() |
| 49 | if global_value.platform != "Windows" and global_value.platform != "Linux": |
| 50 | printf("platform error: platform is not windows or linux!") |
| 51 | printf("platform.system() = %s" % platform.system()) |
| 52 | global_value.logger.error("platform error: platform is not windows or linux!") |
| 53 | global_value.logger.error("platform.system() = %s", platform.system()) |
| 54 | sys.exit(1) |
| 55 | |
| 56 | global_value.logger.info("path = %s, logging_path = %s, platform = %s", global_value.path, global_value.logging_path |
| 57 | , global_value.platform) |
| 58 | |
| 59 | global_value.pars_macro_info() |
| 60 | |
| 61 | if global_value.platform == "Windows": # windows |
| 62 | tableconstructor_win.parse_segment_info_win() |
| 63 | elif global_value.platform == "Linux": # linux |
| 64 | tableconstructor.pars_segment_info() |
| 65 | else: |
| 66 | pass |
| 67 | |
| 68 | tableconstructor.parse_lid_table() |
| 69 | tableconstructor.parse_lid_item_data() |
| 70 | tableconstructor.statistic_lid_item_data() |
| 71 | |
| 72 | # tmp write ltable for NVDB test |
| 73 | # tableconstructor.write_logical_table() |
| 74 | |
| 75 | # sort ,key is lid |
| 76 | sort_key = operator.attrgetter('lid') |
| 77 | logical_data_item_table.sort(key=sort_key) |
| 78 | |
| 79 | # # assign entry |
| 80 | global_value.logger.info("====================") |
| 81 | global_value.logger.info("nvram_gen_assign_entry") |
| 82 | gen_assign_entry.nvram_gen_assign_entry() |
| 83 | |
| 84 | # gen nvram_cache_info.c and nvram_cache_info.h |
| 85 | global_value.logger.info("====================") |
| 86 | global_value.logger.info("nvram_gen_cache_info") |
| 87 | gen_cache_info.nvram_gen_cache_info() |
| 88 | |
| 89 | # gen custom_nvram_lid_cat.xml |
| 90 | global_value.logger.info("====================") |
| 91 | global_value.logger.info("nvram_gen_cat_xml") |
| 92 | gen_cat_file.nvram_gen_cat_xml() |
| 93 | |
| 94 | # gen ~nvram_lid_information.log and ~nvram_lid_size.log |
| 95 | global_value.logger.info("====================") |
| 96 | global_value.logger.info("nvram_gen_info_size_log") |
| 97 | gen_lid_information.nvram_gen_info_size_log() |
| 98 | |
| 99 | # gen nvram_lid_statistics_bak.h |
| 100 | global_value.logger.info("====================") |
| 101 | global_value.logger.info("nvram_gen_statistic") |
| 102 | gen_statistic.nvram_gen_statistic() |
| 103 | |
| 104 | # gen custom_nvram_restore.c and nvram_restore_dom_new.h |
| 105 | global_value.logger.info("====================") |
| 106 | global_value.logger.info("nvram_gen_restore_function") |
| 107 | sys_cache_generator.nvram_gen_restore_function() # win || linux |
| 108 | |
| 109 | # gen nvram_custpack_table.c and nvram_custpack_table_lid.c |
| 110 | if (global_value.macro & const_value.__MMI_FMI__) and (not global_value.macro & const_value.__L1_STANDALONE__): |
| 111 | global_value.logger.info("====================") |
| 112 | global_value.logger.info("nvram_gen_custpack_table") |
| 113 | custpackhelper.nvram_gen_custpack_table() |
| 114 | |
| 115 | # gen custom_nvram_secro.c and custom_nvram_secro_tbl.c |
| 116 | if True: # global_value.macro & const_value.__VENDOR_RELEASE__: |
| 117 | global_value.logger.info("====================") |
| 118 | global_value.logger.info("nvram_gen_secro") |
| 119 | secupackhelper.nvram_gen_secro() # win || linux |
| 120 | |
| 121 | # gen nvram_ltable_List.h |
| 122 | global_value.logger.info("====================") |
| 123 | global_value.logger.info("nvram_gen_ltable_list") |
| 124 | mcf_ota_helper.nvram_gen_ltable_list() |
| 125 | |
| 126 | # gen nvram_lid_list_for_mcf.h |
| 127 | global_value.logger.info("====================") |
| 128 | global_value.logger.info("nvram_gen_mcf_ota_lid_list") |
| 129 | mcf_ota_helper.nvram_gen_mcf_ota_lid_list() |
| 130 | |
| 131 | global_value.logger.info("====================") |
| 132 | global_value.logger.info("build time check: begin") |
| 133 | # build time check:lid enum overlapping |
| 134 | global_value.logger.info("build time check: lid enum overlapping") |
| 135 | buildtimecheck.check_lid_enum_overlapping() |
| 136 | buildtimecheck.check_lid_fileprefix_overlapping() |
| 137 | # build time check:write protect attr white list |
| 138 | global_value.logger.info("build time check: write protect attr white list ") |
| 139 | buildtimecheck.check_write_protect() |
| 140 | # build time check:cate attr confilicts |
| 141 | global_value.logger.info("build time check: cate attr confilicts") |
| 142 | buildtimecheck.nvram_gen_check_cate_attr_conflicts() |
| 143 | # build time check:hash key check |
| 144 | if (global_value.macro & const_value.__NVRAM_LID_HASH_CHECK__) and (global_value.macro & const_value.__MTK_INTERNAL__): |
| 145 | global_value.logger.info("build time check: hash key check") |
| 146 | buildtimecheck.check_lid_hash_key() |
| 147 | # build time check:special lid parameter |
| 148 | global_value.logger.info("build time check: special lid parameter") |
| 149 | buildtimecheck.check_special_lid_parameter() |
| 150 | global_value.logger.info("build time check: end") |
| 151 | |
| 152 | # gen custom_nvram_database.h |
| 153 | global_value.logger.info("build time check: gen custom_nvram_database") |
| 154 | tmp_path = os.path.join(path, "nvram_auto_gen", "custom_nvram_database.h") |
| 155 | print("custom_nvram database path: {}".format(tmp_path) ) |
| 156 | f = open(tmp_path, "w") |
| 157 | f.close() |
| 158 | global_value.logger.info("build time check: end") |
| 159 | |
| 160 | if __name__ == '__main__': |
| 161 | main() |