From 0c9628f6057a1e56803dd71051302b6f4cb3a3fd Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Mon, 23 Mar 2020 17:14:04 +0800 Subject: [PATCH] acrn-config: remove the same parameters and functions from launch_cfg_lib Launch config should relay on library/common.py and launch_cfg_lib, then remove the duplicate parameters and functions. Tracked-On: #3854 Signed-off-by: Wei Liu Acked-by: Victor Sun Acked-by: Terry Zou --- misc/acrn-config/launch_config/com.py | 7 +- .../launch_config/launch_cfg_gen.py | 30 ++- misc/acrn-config/launch_config/launch_item.py | 31 +-- misc/acrn-config/library/launch_cfg_lib.py | 218 ++---------------- 4 files changed, 47 insertions(+), 239 deletions(-) diff --git a/misc/acrn-config/launch_config/com.py b/misc/acrn-config/launch_config/com.py index 374a3f8d5..354dbf0d3 100644 --- a/misc/acrn-config/launch_config/com.py +++ b/misc/acrn-config/launch_config/com.py @@ -4,6 +4,7 @@ # import launch_cfg_lib +import common import pt @@ -29,7 +30,7 @@ def tap_uos_net(names, virt_io, vmid, config): uos_type = names['uos_types'][vmid] board_name = names['board_name'] - vm_name = launch_cfg_lib.undline_name(uos_type).lower() + vm_name = common.undline_name(uos_type).lower() if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"): i = 0 @@ -276,7 +277,7 @@ def launch_begin(names, virt_io, vmid, config): board_name = names['board_name'] uos_type = names['uos_types'][vmid] - launch_uos = launch_cfg_lib.undline_name(uos_type).lower() + launch_uos = common.undline_name(uos_type).lower() tap_network(virt_io, vmid, config) run_container(board_name, uos_type, config) print("function launch_{}()".format(launch_uos), file=config) @@ -299,7 +300,7 @@ def uos_launch(names, args, virt_io, vmid, config): gvt_args = args['gvt_args'][vmid] uos_type = names['uos_types'][vmid] - launch_uos = launch_cfg_lib.undline_name(uos_type).lower() + launch_uos = common.undline_name(uos_type).lower() board_name = names['board_name'] if 'nuc' in board_name: board_name = 'nuc' diff --git a/misc/acrn-config/launch_config/launch_cfg_gen.py b/misc/acrn-config/launch_config/launch_cfg_gen.py index 9b4471ac4..39beff101 100644 --- a/misc/acrn-config/launch_config/launch_cfg_gen.py +++ b/misc/acrn-config/launch_config/launch_cfg_gen.py @@ -11,8 +11,8 @@ import launch_cfg_lib import com import common -ACRN_PATH = launch_cfg_lib.SOURCE_ROOT_DIR -ACRN_CONFIG_TARGET = ACRN_PATH + '/misc/acrn-config/xmls/config-xmls/' +ACRN_PATH = common.SOURCE_ROOT_DIR +ACRN_CONFIG_DEF = ACRN_PATH + '/misc/acrn-config/xmls/config-xmls/' def get_launch_item_values(board_info): @@ -64,9 +64,6 @@ def validate_launch_setting(board_info, scenario_info, launch_info): common.BOARD_INFO_FILE = board_info common.SCENARIO_INFO_FILE = scenario_info common.LAUNCH_INFO_FILE = launch_info - launch_cfg_lib.BOARD_INFO_FILE = board_info - launch_cfg_lib.SCENARIO_INFO_FILE = scenario_info - launch_cfg_lib.LAUNCH_INFO_FILE = launch_info # init available pt devices and get selected pt devices pt_avl = AvailablePthru(board_info) @@ -94,7 +91,7 @@ def ui_entry_api(board_info, scenario_info, launch_info): err_dic = {} arg_list = ['launch_cfg_gen.py', '--board', board_info, '--scenario', scenario_info, '--launch', launch_info, '--uosid', '0'] - err_dic = launch_cfg_lib.prepare() + err_dic = common.prepare() if err_dic: return err_dic @@ -111,13 +108,13 @@ def get_names(): names['uos_types'] = uos_types # get board name - (err_dic, board_name) = launch_cfg_lib.get_board_name() + (err_dic, board_name) = common.get_board_name() if err_dic: return (err_dic, names) names['board_name'] = board_name # get scenario name - (err_dic, scenario_name) = launch_cfg_lib.get_scenario_name() + (err_dic, scenario_name) = common.get_scenario_name() if err_dic: return (err_dic, names) names['scenario_name'] = scenario_name @@ -146,17 +143,16 @@ def main(args): This is main function to start generate launch script :param args: it is a command line args for the script """ - global ACRN_CONFIG_TARGET # get parameters (err_dic, board_info_file, scenario_info_file, launch_info_file, vm_th, output_folder) = launch_cfg_lib.get_param(args) if err_dic: return err_dic if output_folder: - ACRN_CONFIG_TARGET = os.path.abspath(output_folder) + '/' + common.ACRN_CONFIG_TARGET = os.path.abspath(output_folder) + '/' # check env - err_dic = launch_cfg_lib.prepare() + err_dic = common.prepare() if err_dic: return err_dic @@ -168,9 +164,6 @@ def main(args): common.BOARD_INFO_FILE = board_info_file common.SCENARIO_INFO_FILE = scenario_info_file common.LAUNCH_INFO_FILE = launch_info_file - launch_cfg_lib.BOARD_INFO_FILE = board_info_file - launch_cfg_lib.SCENARIO_INFO_FILE = scenario_info_file - launch_cfg_lib.LAUNCH_INFO_FILE = launch_info_file # get post vm dic post_num_list = launch_cfg_lib.get_post_num_list() @@ -207,8 +200,11 @@ def main(args): # create output directory board_name = names['board_name'] - output = ACRN_CONFIG_TARGET + '/' + board_name + '/output/' - launch_cfg_lib.mkdir(output) + if common.ACRN_CONFIG_TARGET: + output = common.ACRN_CONFIG_TARGET + '/' + board_name + '/output/' + else: + output = ACRN_CONFIG_DEF + '/' + board_name + '/output/' + common.mkdir(output) # generate launch script if vm_th: @@ -241,4 +237,4 @@ if __name__ == '__main__': err_dic = main(ARGS) if err_dic: for err_k, err_v in err_dic.items(): - launch_cfg_lib.print_red("{}: {}".format(err_k, err_v), err=True) + common.print_red("{}: {}".format(err_k, err_v), err=True) diff --git a/misc/acrn-config/launch_config/launch_item.py b/misc/acrn-config/launch_config/launch_item.py index 59743e63c..1575b8b96 100644 --- a/misc/acrn-config/launch_config/launch_item.py +++ b/misc/acrn-config/launch_config/launch_item.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: BSD-3-Clause # +import common import board_cfg_lib import launch_cfg_lib @@ -15,16 +16,16 @@ class AcrnDmArgs: self.launch_info = launch_info def get_args(self): - self.args["uos_type"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "uos_type") - self.args["rtos_type"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "rtos_type") - self.args["mem_size"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "mem_size") - self.args["gvt_args"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "gvt_args") - self.args["vbootloader"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "vbootloader") - self.args["vuart0"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "vuart0") - self.args["cpu_sharing"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "cpu_sharing") - self.args["pm_channel"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "poweroff_channel") - self.args["off_pcpus"] = launch_cfg_lib.get_leaf_tag_map(self.scenario_info, "vcpu_affinity", "pcpu_id") - self.args["xhci"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "usb_xhci") + self.args["uos_type"] = common.get_leaf_tag_map(self.launch_info, "uos_type") + self.args["rtos_type"] = common.get_leaf_tag_map(self.launch_info, "rtos_type") + self.args["mem_size"] = common.get_leaf_tag_map(self.launch_info, "mem_size") + self.args["gvt_args"] = common.get_leaf_tag_map(self.launch_info, "gvt_args") + self.args["vbootloader"] = common.get_leaf_tag_map(self.launch_info, "vbootloader") + self.args["vuart0"] = common.get_leaf_tag_map(self.launch_info, "vuart0") + self.args["cpu_sharing"] = common.get_leaf_tag_map(self.launch_info, "cpu_sharing") + self.args["pm_channel"] = common.get_leaf_tag_map(self.launch_info, "poweroff_channel") + self.args["off_pcpus"] = common.get_leaf_tag_map(self.scenario_info, "vcpu_affinity", "pcpu_id") + self.args["xhci"] = common.get_leaf_tag_map(self.launch_info, "usb_xhci") def check_item(self): rootfs = board_cfg_lib.get_rootfs(self.board_info) @@ -42,7 +43,7 @@ class AvailablePthru(): def __init__(self, board_info): self.board_info = board_info - (self.bdf_desc_map, self.bdf_vpid_map) = launch_cfg_lib.get_pci_info(board_info) + (self.bdf_desc_map, self.bdf_vpid_map) = board_cfg_lib.get_pci_info(board_info) def get_bdf_vpid_map(self): return self.bdf_vpid_map @@ -156,10 +157,10 @@ class VirtioDeviceSelect(): self.launch_info = launch_info def get_virtio(self): - self.dev["input"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "input") - self.dev["block"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "block") - self.dev["network"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "network") - self.dev["console"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "console") + self.dev["input"] = common.get_leaf_tag_map(self.launch_info, "virtio_devices", "input") + self.dev["block"] = common.get_leaf_tag_map(self.launch_info, "virtio_devices", "block") + self.dev["network"] = common.get_leaf_tag_map(self.launch_info, "virtio_devices", "network") + self.dev["console"] = common.get_leaf_tag_map(self.launch_info, "virtio_devices", "console") def check_virtio(self): launch_cfg_lib.check_block_mount(self.dev["block"]) diff --git a/misc/acrn-config/library/launch_cfg_lib.py b/misc/acrn-config/library/launch_cfg_lib.py index a662f206a..66fa474bf 100644 --- a/misc/acrn-config/library/launch_cfg_lib.py +++ b/misc/acrn-config/library/launch_cfg_lib.py @@ -8,11 +8,6 @@ import getopt import common import board_cfg_lib -SOURCE_ROOT_DIR = common.SOURCE_ROOT_DIR -BOARD_INFO_FILE = "board_info.txt" -SCENARIO_INFO_FILE = "" -LAUNCH_INFO_FILE = "" - ERR_LIST = {} BOOT_TYPE = ['no', 'vsbl', 'ovmf'] RTOS_TYPE = ['no', 'Soft RT', 'Hard RT'] @@ -61,29 +56,6 @@ PM_CHANNEL_DIC = { MOUNT_FLAG_DIC = {} -def prepare(): - """ Check environment """ - return common.prepare() - - -def print_yel(msg, warn=False): - """ - Print the message with color of yellow - :param msg: the stings which will be output to STDOUT - :param warn: the condition if needs to be output the color of yellow with 'Warning' - """ - common.print_yel(msg, warn) - - -def print_red(msg, err=False): - """ - Print the message with color of red - :param msg: the stings which will be output to STDOUT - :param err: the condition if needs to be output the color of red with 'Error' - """ - common.print_red(msg, err) - - def usage(file_name): """ This is usage for how to use this tool """ print("usage= {} [h]".format(file_name), end="") @@ -178,7 +150,7 @@ def get_post_num_list(): post_vm_list = [] # get post vm number - root = common.get_config_root(LAUNCH_INFO_FILE) + root = common.get_config_root(common.LAUNCH_INFO_FILE) for item in root: if item.tag == "uos": post_vm_list.append(int(item.attrib['id'])) @@ -207,62 +179,11 @@ def get_post_vm_cnt(): Get board name from launch.xml at fist line :param scenario_file: it is a file what contains scenario information for script to read from """ - launch_vm_count = launch_vm_cnt(LAUNCH_INFO_FILE) - post_vm_count = post_vm_cnt(SCENARIO_INFO_FILE) + launch_vm_count = launch_vm_cnt(common.LAUNCH_INFO_FILE) + post_vm_count = post_vm_cnt(common.SCENARIO_INFO_FILE) return (launch_vm_count, post_vm_count) -def get_pci_info(board_info): - pci_bdf_vpid = {} - pci_vid_start = False - pci_vid_end = False - pci_desc = {} - pci_start = False - pci_end = False - - with open(board_info, 'r') as f: - while True: - line = f.readline() - if not line: - break - - s = " " - if s.join(line.split()[0:2]) == "": - pci_start = True - pci_end = False - continue - - if s.join(line.split()[0:2]) == "": - pci_start = False - pci_end = True - continue - - # all pci device wiht description - if pci_start and not pci_end: - if "Region" in line and "Memory at" in line: - continue - bdf = line.split()[0] - pci_desc[bdf] = line - - if s.join(line.split()[0:2]) == "": - pci_vid_start = True - pci_vid_end = False - continue - - if s.join(line.split()[0:2]) == "": - pci_vid_start = False - pci_vid_end = True - continue - - # all pci device with vid/pid and bdf - if pci_vid_start and not pci_vid_end: - bdf_str = line.split()[0] - vid_pid = line.split()[2] - pci_bdf_vpid[bdf_str] = vid_pid - - return (pci_desc, pci_bdf_vpid) - - def get_avl_dev_info(bdf_desc_map, pci_sub_class): tmp_pci_desc = [] @@ -275,70 +196,18 @@ def get_avl_dev_info(bdf_desc_map, pci_sub_class): return tmp_pci_desc -def get_info(board_info, msg_s, msg_e): - """ - Get information which specify by argument - :param board_info: it is a file what contains board information for script to read from - :param msg_s: it is a pattern of key stings what start to match from board information - :param msg_e: it is a pattern of key stings what end to match from board information - """ - info_lines = board_cfg_lib.get_info(board_info, msg_s, msg_e) - return info_lines - - -def get_rootdev_info(board_info): - """ - Get root devices from board info - :param board_info: it is a file what contains board information for script to read from - :return: root devices list - """ - rootdev_list = [] - rootdev_info = board_cfg_lib.get_info(board_info, "", "") - - if rootdev_info == None: - return rootdev_list - - for rootdev_line in rootdev_info: - if not rootdev_line: - break - - if not board_cfg_lib.handle_root_dev(rootdev_line): - continue - - root_dev = rootdev_line.strip().split(':')[0] - rootdev_list.append(root_dev) - - return rootdev_list - - -def get_scenario_name(): - """ - Get board name from scenario.xml at fist line - :param scenario_file: it is a file what contains scenario information for script to read from - """ - return common.get_scenario_name() - - -def get_board_name(): - """ - Get board name from board.xml at fist line - :param board_info: it is a file what contains board information for script to read from - """ - return common.get_board_name() - - def is_config_file_match(): match = True # check if the board config match scenario config - (err_dic, scenario_for_board) = common.get_xml_attrib(SCENARIO_INFO_FILE, "board") - (err_dic, board_name) = common.get_xml_attrib(BOARD_INFO_FILE, "board") + (err_dic, scenario_for_board) = common.get_xml_attrib(common.SCENARIO_INFO_FILE, "board") + (err_dic, board_name) = common.get_xml_attrib(common.BOARD_INFO_FILE, "board") if scenario_for_board != board_name: err_dic['scenario config: Not match'] = "The board xml and scenario xml should be matched!" match = False # check if the board config match launch config - (err_dic, launch_for_board) = common.get_xml_attrib(LAUNCH_INFO_FILE, "board") + (err_dic, launch_for_board) = common.get_xml_attrib(common.LAUNCH_INFO_FILE, "board") if launch_for_board != board_name: err_dic['launch config: Not match'] = "The board xml and launch xml should be matched!" match = False @@ -346,27 +215,16 @@ def is_config_file_match(): return (err_dic, match) -def get_leaf_tag_map(info_file, prime_item, item=''): - """ - :param info_file: some configurations in the info file - :param prime_item: the prime item in xml file - :param item: the item in xml file - :return: dictionary which item value could be indexed by vmid - """ - vmid_item_dic = common.get_leaf_tag_map(info_file, prime_item, item) - return vmid_item_dic - - def get_scenario_uuid(): # {id_num:uuid} (id_num:0~max) scenario_uuid_dic = {} - scenario_uuid_dic = get_leaf_tag_map(SCENARIO_INFO_FILE, 'uuid') + scenario_uuid_dic = common.get_leaf_tag_map(common.SCENARIO_INFO_FILE, 'uuid') return scenario_uuid_dic def get_sos_vmid(): - load_dic = get_leaf_tag_map(SCENARIO_INFO_FILE, "load_order") + load_dic = common.get_leaf_tag_map(common.SCENARIO_INFO_FILE, "load_order") sos_id = '' for idx,load_order in load_dic.items(): @@ -379,7 +237,7 @@ def get_sos_vmid(): def get_bdf_from_tag(config_file, branch_tag, tag_str): bdf_list = {} - bdf_list = get_leaf_tag_map(config_file, branch_tag, tag_str) + bdf_list = common.get_leaf_tag_map(config_file, branch_tag, tag_str) # split b:d:f from pci description for idx, bdf_v in bdf_list.items(): @@ -409,7 +267,7 @@ def get_uos_type(): """ Get uos name from launch.xml at fist line """ - uos_types = get_leaf_tag_map(LAUNCH_INFO_FILE, "uos_type") + uos_types = common.get_leaf_tag_map(common.LAUNCH_INFO_FILE, "uos_type") return uos_types @@ -506,40 +364,6 @@ def args_aval_check(arg_list, item, avl_list): i_cnt += 1 -def get_cpu_processor_num(): - """ - get cpu processor number from config file which is dumped from native board - :return: integer number of cpu processor - """ - cpu_lines = board_cfg_lib.get_info(BOARD_INFO_FILE, "", "") - - for cpu_line in cpu_lines: - cpu_processor_num = len(cpu_line.split(',')) - - return cpu_processor_num - - -def get_total_mem(): - """ - get total memory size from config file which is dumped from native board - :return: integer number of total memory size, Unit: MByte - """ - scale_to_mb = 1 - total_mem_mb = scale_to_mb - mem_lines = board_cfg_lib.get_info(BOARD_INFO_FILE, "", "") - for mem_line in mem_lines: - mem_info_list = mem_line.split() - - if len(mem_info_list) <= 1: - return total_mem_mb - - if mem_info_list[1] == "kB": - scale_to_mb = 1024 - - total_mem_mb = int(mem_info_list[0]) / scale_to_mb - return total_mem_mb - - def mem_size_check(arg_list, item): """ check memory size list which are set from webUI @@ -548,7 +372,7 @@ def mem_size_check(arg_list, item): :return: None """ # get total memory information - total_mem_mb = get_total_mem() + total_mem_mb = board_cfg_lib.get_total_mem() # available check i_cnt = 1 @@ -619,18 +443,9 @@ def get_pt_dev(): 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) - - def get_vuart1_from_scenario(vmid): """Get the vmid's vuart1 base""" - vuart1 = board_cfg_lib.get_vuart_info_id(SCENARIO_INFO_FILE, 1) + vuart1 = board_cfg_lib.get_vuart_info_id(common.SCENARIO_INFO_FILE, 1) return vuart1[vmid]['base'] @@ -651,7 +466,7 @@ def pt_devs_check_audio(audio_map, audio_codec_map): def check_block_mount(virtio_blk_dic): - blk_dev_list = board_cfg_lib.get_rootfs(BOARD_INFO_FILE) + blk_dev_list = board_cfg_lib.get_rootfs(common.BOARD_INFO_FILE) for vmid in list(virtio_blk_dic.keys()): mount_flags = [] for blk in virtio_blk_dic[vmid]: @@ -686,7 +501,7 @@ def cpu_sharing_check(cpu_sharing, item): vm_cpu_share = [] vm_cpu_share_consistent = True - cpu_affinity = get_leaf_tag_map(SCENARIO_INFO_FILE, "vcpu_affinity", "pcpu_id") + cpu_affinity = common.get_leaf_tag_map(common.SCENARIO_INFO_FILE, "vcpu_affinity", "pcpu_id") for vm_i in cpu_affinity.keys(): for cpu in cpu_affinity[vm_i]: if cpu in use_cpus: @@ -733,8 +548,3 @@ def bdf_duplicate_check(bdf_dic): return else: bdf_used.append(dev_bdf) - - -def mkdir(path): - - common.mkdir(path)