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 <weix.w.liu@intel.com>
Acked-by: Victor Sun <victor.sun@intel.com>
This commit is contained in:
Wei Liu 2019-12-09 14:33:49 +08:00 committed by wenlingz
parent 212d030b9a
commit deb5ed1f76
6 changed files with 70 additions and 95 deletions

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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']

View File

@ -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