From deb5ed1f76c4579a3da48a5f8eccfd71c222cfe1 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Mon, 9 Dec 2019 14:33:49 +0800 Subject: [PATCH] acrn-config: unify get_vuart_info_id api in config tool 1. unify get_vuart_info_id/get_vuart_id api in board/scenario/launch config tool. 2. if vm use 'vuart1(tty)' method to power off, make sure this vm have select the vuart1 'SOS_COM2_BASE'. Tracked-On: #3854 Signed-off-by: Wei Liu Acked-by: Victor Sun --- misc/acrn-config/board_config/misc_cfg_h.py | 17 ++----- misc/acrn-config/launch_config/com.py | 6 +++ misc/acrn-config/library/board_cfg_lib.py | 42 +--------------- misc/acrn-config/library/common.py | 50 ++++++++++++++++++++ misc/acrn-config/library/launch_cfg_lib.py | 8 +++- misc/acrn-config/library/scenario_cfg_lib.py | 42 +--------------- 6 files changed, 70 insertions(+), 95 deletions(-) diff --git a/misc/acrn-config/board_config/misc_cfg_h.py b/misc/acrn-config/board_config/misc_cfg_h.py index 554ab2c0e..eeae6503c 100644 --- a/misc/acrn-config/board_config/misc_cfg_h.py +++ b/misc/acrn-config/board_config/misc_cfg_h.py @@ -14,17 +14,11 @@ MISC_CFG_END = """#endif /* MISC_CFG_H */""" class Vuart: - t_vm_id = [] - t_vuart_id = [] - v_type = [] - v_base = [] - v_irq = [] - - def style_check_1(self): - self.v_irq = [] - - def style_check_2(self): - self.v_irq = [] + t_vm_id = {} + t_vuart_id = {} + v_type = {} + v_base = {} + v_irq = {} def sos_bootarg_diff(sos_cmdlines, config): @@ -159,7 +153,6 @@ def generate_file(config): print("#define SOS_COM2_BASE\t\t{}U".format(vuart1_port_base), file=config) print("#define SOS_COM2_IRQ\t\t{}U".format(vuart1_irq), file=config) - # sos boot command line print("", file=config) if "SOS_VM" in vm_types: diff --git a/misc/acrn-config/launch_config/com.py b/misc/acrn-config/launch_config/com.py index 44da3cb64..246d13ee0 100644 --- a/misc/acrn-config/launch_config/com.py +++ b/misc/acrn-config/launch_config/com.py @@ -531,6 +531,12 @@ def dm_arg_set(names, sel, virt_io, dm, vmid, config): # pm_channel set if dm['pm_channel'][vmid] and dm['pm_channel'][vmid] != None: pm_key = dm['pm_channel'][vmid] + if pm_key == "vuart1(tty)": + vuart_base = launch_cfg_lib.get_vuart1_from_scenario(sos_vmid + vmid) + if vuart_base == "INVALID_COM_BASE": + err_key = "uos:id={}:poweroff_channel".format(vmid) + launch_cfg_lib.ERR_LIST[err_key] = "vuart1 of VM{} in scenario file should select 'SOS_COM2_BASE'".format(sos_vmid + vmid) + return print(" {} \\".format(launch_cfg_lib.PM_CHANNEL_DIC[pm_key]), file=config) # XHCI args set diff --git a/misc/acrn-config/library/board_cfg_lib.py b/misc/acrn-config/library/board_cfg_lib.py index 3367b33fd..f419f0215 100644 --- a/misc/acrn-config/library/board_cfg_lib.py +++ b/misc/acrn-config/library/board_cfg_lib.py @@ -384,29 +384,6 @@ def get_board_private_vuart(branch_tag, tag_console): return (err_dic, vuart0_console_dic, vuart1_console_dic) -def get_vuart_id(tmp_vuart, leaf_tag, leaf_text): - """ - Get all vuart id member of class - :param leaf_tag: key pattern of item tag - :param tmp_vuart: a dictionary to store member:value - :param leaf_text: key pattern of item tag's value - :return: a dictionary to which stored member:value - """ - if leaf_tag == "type": - tmp_vuart['type'] = leaf_text - if leaf_tag == "base": - tmp_vuart['base'] = leaf_text - if leaf_tag == "irq": - tmp_vuart['irq'] = leaf_text - - if leaf_tag == "target_vm_id": - tmp_vuart['target_vm_id'] = leaf_text - if leaf_tag == "target_uart_id": - tmp_vuart['target_uart_id'] = leaf_text - - return tmp_vuart - - def get_vuart_info_id(config_file, idx): """ Get vuart information by vuart id indexx @@ -414,24 +391,7 @@ def get_vuart_info_id(config_file, idx): :param idx: vuart index in range: [0,1] :return: dictionary which stored the vuart-id """ - tmp_tag = [] - vm_id = 0 - root = common.get_config_root(config_file) - for item in root: - for sub in item: - tmp_vuart = {} - for leaf in sub: - if sub.tag == "vuart" and int(sub.attrib['id']) == idx: - tmp_vuart = get_vuart_id(tmp_vuart, leaf.tag, leaf.text) - - # append vuart for each vm - if tmp_vuart and sub.tag == "vuart": - #tmp_vuart[vm_id] = tmp_vuart - tmp_tag.append(tmp_vuart) - - if item.tag == "vm": - vm_id += 1 - + tmp_tag = common.get_vuart_info_id(config_file, idx) return tmp_tag diff --git a/misc/acrn-config/library/common.py b/misc/acrn-config/library/common.py index 3845415a8..ed7f7bbde 100644 --- a/misc/acrn-config/library/common.py +++ b/misc/acrn-config/library/common.py @@ -627,3 +627,53 @@ def undline_name(name): name_str = "_".join(name_str.split()).upper() return name_str + + +def get_vuart_id(tmp_vuart, leaf_tag, leaf_text): + """ + Get all vuart id member of class + :param tmp_vuart: a dictionary to store member:value + :param leaf_tag: key pattern of item tag + :param leaf_text: key pattern of item tag's value + :return: a dictionary to which stored member:value + """ + if leaf_tag == "type": + tmp_vuart['type'] = leaf_text + if leaf_tag == "base": + tmp_vuart['base'] = leaf_text + if leaf_tag == "irq": + tmp_vuart['irq'] = leaf_text + + if leaf_tag == "target_vm_id": + tmp_vuart['target_vm_id'] = leaf_text + if leaf_tag == "target_uart_id": + tmp_vuart['target_uart_id'] = leaf_text + + return tmp_vuart + + +def get_vuart_info_id(config_file, idx): + """ + Get vuart information by vuart id indexx + :param config_file: it is a file what contains information for script to read from + :param idx: vuart index in range: [0,1] + :return: dictionary which stored the vuart-id + """ + tmp_tag = {} + vm_id = 0 + root = get_config_root(config_file) + for item in root: + for sub in item: + tmp_vuart = {} + for leaf in sub: + if sub.tag == "vuart" and int(sub.attrib['id']) == idx: + tmp_vuart = get_vuart_id(tmp_vuart, leaf.tag, leaf.text) + + # append vuart for each vm + if tmp_vuart and sub.tag == "vuart": + tmp_tag[vm_id] = tmp_vuart + + if item.tag == "vm": + vm_id += 1 + + return tmp_tag diff --git a/misc/acrn-config/library/launch_cfg_lib.py b/misc/acrn-config/library/launch_cfg_lib.py index 1f594bab3..dd7650dc0 100644 --- a/misc/acrn-config/library/launch_cfg_lib.py +++ b/misc/acrn-config/library/launch_cfg_lib.py @@ -53,7 +53,7 @@ PM_CHANNEL_DIC = { None:'', 'IOC':'--pm_notify_channel ioc', 'PowerButton':'--pm_notify_channel power_button', - 'vuart1(pty)':'--pm_notify_channel uart \\\n\t--pm_by_vuart pty,/run/acrn/life_mngr_$vm_name \\\n\t-l com2,/run/acrn/life_mngr_$vm_name', + 'vuart1(pty)':'--pm_notify_channel uart \\\n --pm_by_vuart pty,/run/acrn/life_mngr_$vm_name \\\n -l com2,/run/acrn/life_mngr_$vm_name', 'vuart1(tty)':'--pm_notify_channel uart --pm_by_vuart tty,/dev/ttyS1', } @@ -596,3 +596,9 @@ def undline_name(name): :return: name_str which contain'_' """ return common.undline_name(name) + + +def get_vuart1_from_scenario(vmid): + """Get the vmid's vuart1 base""" + vuart1 = common.get_vuart_info_id(SCENARIO_INFO_FILE, 1) + return vuart1[vmid]['base'] diff --git a/misc/acrn-config/library/scenario_cfg_lib.py b/misc/acrn-config/library/scenario_cfg_lib.py index a452c3af9..f03bd861a 100644 --- a/misc/acrn-config/library/scenario_cfg_lib.py +++ b/misc/acrn-config/library/scenario_cfg_lib.py @@ -670,29 +670,6 @@ def gen_patch(srcs_list, scenario_name): return err_dic -def get_vuart_id(tmp_vuart, leaf_tag, leaf_text): - """ - Get all vuart id member of class - :param tmp_vuart: a dictionary to store member:value - :param leaf_tag: key pattern of item tag - :param leaf_text: key pattern of item tag's value - :return: a dictionary to which stored member:value - """ - if leaf_tag == "type": - tmp_vuart['type'] = leaf_text - if leaf_tag == "base": - tmp_vuart['base'] = leaf_text - if leaf_tag == "irq": - tmp_vuart['irq'] = leaf_text - - if leaf_tag == "target_vm_id": - tmp_vuart['target_vm_id'] = leaf_text - if leaf_tag == "target_uart_id": - tmp_vuart['target_uart_id'] = leaf_text - - return tmp_vuart - - def get_vuart_info_id(config_file, idx): """ Get vuart information by vuart id indexx @@ -700,23 +677,7 @@ def get_vuart_info_id(config_file, idx): :param idx: vuart index in range: [0,1] :return: dictionary which stored the vuart-id """ - tmp_tag = {} - vm_id = 0 - root = common.get_config_root(config_file) - for item in root: - for sub in item: - tmp_vuart = {} - for leaf in sub: - if sub.tag == "vuart" and int(sub.attrib['id']) == idx: - tmp_vuart = get_vuart_id(tmp_vuart, leaf.tag, leaf.text) - - # append vuart for each vm - if tmp_vuart and sub.tag == "vuart": - tmp_tag[vm_id] = tmp_vuart - - if item.tag == "vm": - vm_id += 1 - + tmp_tag = common.get_vuart_info_id(config_file, idx) return tmp_tag @@ -737,7 +698,6 @@ def avl_vuart_ui_select(scenario_info): key = "vm={},vuart=1,base".format(vm_i) tmp_vuart[key] = ['INVALID_COM_BASE', 'COM2_BASE'] - #print(tmp_vuart) return tmp_vuart