From a2430f131319d85b18668fd9098d04611fd04a78 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Thu, 17 Oct 2019 10:23:56 +0800 Subject: [PATCH] acrn-config: refine board name with undline_name api Sometimes character '-' or space need to be converted to '_' to make string format uniformed. Add this common api to satisfy such requirment and refine the code for board name generating. Tracked-On: #3852 Signed-off-by: Wei Liu Acked-by: Victor Sun --- .../acrn-config/board_config/pci_devices_h.py | 19 +---------------- misc/acrn-config/board_config/ve820_c.py | 21 ++++--------------- misc/acrn-config/launch_config/com.py | 7 ++++--- misc/acrn-config/library/board_cfg_lib.py | 9 ++++++++ misc/acrn-config/library/common.py | 16 ++++++++++++++ misc/acrn-config/library/launch_cfg_lib.py | 9 ++++++++ 6 files changed, 43 insertions(+), 38 deletions(-) diff --git a/misc/acrn-config/board_config/pci_devices_h.py b/misc/acrn-config/board_config/pci_devices_h.py index 7b1de73b3..cf7d9e9a3 100644 --- a/misc/acrn-config/board_config/pci_devices_h.py +++ b/misc/acrn-config/board_config/pci_devices_h.py @@ -61,23 +61,6 @@ def parser_pci(): return (pci_dev_dic, pci_bar_dic, sub_name_count) - -def undline_name(name): - """ - This convert name which has contain '-' to '_' - :param name: name which contain '-' and ' ' - :return: name_str which contain'_' - """ - # convert '-' to '_' in name string - name_str = "_".join(name.split('-')).upper() - - # stitch '_' while ' ' in name string - if ' ' in name_str: - name_str = "_".join(name_str.split()).upper() - - return name_str - - def write_pbdf(i_cnt, bdf, subname, config): """ Parser and generate pbdf @@ -91,7 +74,7 @@ def write_pbdf(i_cnt, bdf, subname, config): tmp_sub_name = "_".join(subname.split()).upper() else: if '-' in subname: - tmp_sub_name = undline_name(subname) + "_" + str(i_cnt) + tmp_sub_name = board_cfg_lib.undline_name(subname) + "_" + str(i_cnt) else: tmp_sub_name = "_".join(subname.split()).upper() + "_" + str(i_cnt) diff --git a/misc/acrn-config/board_config/ve820_c.py b/misc/acrn-config/board_config/ve820_c.py index f95bdef09..bf3bbd8ce 100644 --- a/misc/acrn-config/board_config/ve820_c.py +++ b/misc/acrn-config/board_config/ve820_c.py @@ -11,19 +11,6 @@ TOTAL_MEM_SIZE = 4 * 1024 * 1024 * 1024 LOW_MEM_TO_PCI_HOLE = 0x20000000 -def undline_board_name(board_name): - """ - This convert board name which has contain '-' to '_' - :param board_name: - :return: - """ - name_list = board_name - if '-' in board_name: - name_list = "_".join(board_name.split('-')) - - return name_list - - def ve820_per_launch(config, hpa_size): """ Start to generate board.c @@ -33,7 +20,7 @@ def ve820_per_launch(config, hpa_size): if err_dic: return err_dic - board_name = undline_board_name(board_name) + board_name = board_cfg_lib.undline_name(board_name) low_mem_to_pci_hole_len = '0xA0000000' low_mem_to_pci_hole = '0x20000000' @@ -46,9 +33,9 @@ def ve820_per_launch(config, hpa_size): print("#include ", file=config) print("#include ", file=config) print("", file=config) - print("#define VE820_ENTRIES_{}\t{}U".format(board_name.upper(), 5), file=config) + print("#define VE820_ENTRIES_{}\t{}U".format(board_name, 5), file=config) print("static const struct e820_entry ve820_entry[{}] = {{".format( - "VE820_ENTRIES_{}".format(board_name.upper())), file=config) + "VE820_ENTRIES_{}".format(board_name)), file=config) print("\t{\t/* usable RAM under 1MB */", file=config) print("\t\t.baseaddr = 0x0UL,", file=config) print("\t\t.length = 0xF0000UL,\t\t/* 960KB */", file=config) @@ -96,7 +83,7 @@ def ve820_per_launch(config, hpa_size): print("*/", file=config) print("void create_prelaunched_vm_e820(struct acrn_vm *vm)", file=config) print("{", file=config) - print("\tvm->e820_entry_num = VE820_ENTRIES_{};".format(board_name.upper()), file=config) + print("\tvm->e820_entry_num = VE820_ENTRIES_{};".format(board_name), file=config) print("\tvm->e820_entries = ve820_entry;", file=config) print("}", file=config) diff --git a/misc/acrn-config/launch_config/com.py b/misc/acrn-config/launch_config/com.py index fe8af8a44..aa8bd0848 100644 --- a/misc/acrn-config/launch_config/com.py +++ b/misc/acrn-config/launch_config/com.py @@ -21,6 +21,7 @@ def tap_uos_net(names, vmid, config): uos_type = names['uos_types'][vmid] board_name = names['board_name'] + vm_name = launch_cfg_lib.undline_name(uos_type).lower() if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"): if board_name in ("apl-mrb", "apl-up2"): print('if [ ! -f "/data/$3/$3.img" ]; then', file=config) @@ -35,7 +36,7 @@ def tap_uos_net(names, vmid, config): print("", file=config) if uos_type in ("VXWORKS", "ZEPHYR", "WINDOWS"): - print("vm_name={}_vm$1".format(uos_type), file=config) + print("vm_name={}_vm$1".format(vm_name), file=config) if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"): if board_name in ("apl-mrb", "apl-up2"): @@ -231,7 +232,7 @@ def log_level_set(uos_type, config): def launch_begin(board_name, uos_type, config): - launch_uos = '_'.join(uos_type.lower().split()) + launch_uos = launch_cfg_lib.undline_name(board_name).lower() run_container(board_name, uos_type, config) print("function launch_{}()".format(launch_uos), file=config) print("{", file=config) @@ -274,7 +275,7 @@ def uos_launch(names, args, vmid, config): board_name = names['board_name'] gvt_args = args['gvt_args'][vmid] uos_type = names['uos_types'][vmid] - launch_uos = '_'.join(uos_type.lower().split()) + launch_uos = launch_cfg_lib.undline_name(board_name).lower() if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS") and not is_nuc_clr(names, vmid): diff --git a/misc/acrn-config/library/board_cfg_lib.py b/misc/acrn-config/library/board_cfg_lib.py index 7df3e1ce3..c0af5a0f8 100644 --- a/misc/acrn-config/library/board_cfg_lib.py +++ b/misc/acrn-config/library/board_cfg_lib.py @@ -460,3 +460,12 @@ def get_processor_info(): break return tmp_list + + +def undline_name(name): + """ + This convert name which has contain '-' to '_' + :param name: name which contain '-' and ' ' + :return: name_str which contain'_' + """ + return common.undline_name(name) diff --git a/misc/acrn-config/library/common.py b/misc/acrn-config/library/common.py index 308ca5ebb..6900e4456 100644 --- a/misc/acrn-config/library/common.py +++ b/misc/acrn-config/library/common.py @@ -622,3 +622,19 @@ def get_max_clos(board_file): clos_max = int(line.split(':')[1]) return (cache_support, clos_max) + + +def undline_name(name): + """ + This convert name which has contain '-' to '_' + :param name: name which contain '-' and ' ' + :return: name_str which contain'_' + """ + # convert '-' to '_' in name string + name_str = "_".join(name.split('-')).upper() + + # stitch '_' while ' ' in name string + if ' ' in name_str: + name_str = "_".join(name_str.split()).upper() + + return name_str diff --git a/misc/acrn-config/library/launch_cfg_lib.py b/misc/acrn-config/library/launch_cfg_lib.py index 5b1d14052..56eb21b59 100644 --- a/misc/acrn-config/library/launch_cfg_lib.py +++ b/misc/acrn-config/library/launch_cfg_lib.py @@ -585,3 +585,12 @@ def get_pt_dev(): cap_pt = PASSTHRU_DEVS return cap_pt + + +def undline_name(name): + """ + This convert name which has contain '-' to '_' + :param name: name which contain '-' and ' ' + :return: name_str which contain'_' + """ + return common.undline_name(name)