mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-06 03:10:13 +00:00
acrn-config: generate a scenario patch and apply to acrn-hypervisor
1.the script will parse the the board information which already generated, $(scenario).xml modified by user, generate scenario vm configuration and apply to the acrn-hypervisor source code base. 2.parse cpu/memory/ttys/rootfs information from native os and store it to the source code 3.implemnt scenario_config and it's usage usage: scenario_cfg_gen.py --board <board_info_file> -scenario <scenario_info_file> board_info_file : file name of the board info scenario_info_file : file name of the scenario info sample: $ python3 scenario_cfg_gen.py --board ../board-xmls/apl-mrb.xml --scenario ../config-xmls/scenarios/sdc.xml Also improvement board config generate usage: sample: $ python3 board_cfg_gen.py --board ../board-xmls/apl-mrb.xml --scenario ../config-xmls/scenarios/sdc.xml V1-V2: 1). parse board_setting.xml was removed as these configuration will be stitch into scenario configuration 2). parse console for different formats 3). parse epc sections 4). add logical partition rootfs 5). support to parse clos, while webui set to None type 6). support to parse bootargs, while webui set to nul 7). convert '-' to '_' for pci sub class name while generating source file Tracked-On: #3602 Signed-off-by: Wei Liu <weix.w.liu@intel.com> Acked-by: Terry Zou <terry.zou@intel.com>
This commit is contained in:
@@ -4,16 +4,148 @@
|
||||
#
|
||||
|
||||
import parser_lib
|
||||
import subprocess
|
||||
|
||||
IO_MEM_PATH = '/proc/iomem'
|
||||
MEM_PATH = ['/proc/iomem', '/proc/meminfo']
|
||||
TTY_PATH = '/sys/class/tty/'
|
||||
SYS_IRQ_PATH = '/proc/interrupts'
|
||||
CPU_INFO_PATH = '/proc/cpuinfo'
|
||||
|
||||
ttys_type = {
|
||||
'0': 'PORT',
|
||||
'3': 'MMIO',
|
||||
}
|
||||
|
||||
|
||||
def get_system_ram(config):
|
||||
ttys_irqs = []
|
||||
|
||||
def read_ttys_node(path):
|
||||
with open(path, 'rt') as info:
|
||||
ret_value = info.readline().strip()
|
||||
|
||||
return ret_value
|
||||
|
||||
|
||||
def detected_ttys():
|
||||
ttys_cnt = 8
|
||||
tty_used_list = []
|
||||
for s_inc in range(ttys_cnt):
|
||||
cmd = 'stty -F /dev/ttyS{}'.format(s_inc)
|
||||
res = parser_lib.cmd_execute('{}'.format(cmd))
|
||||
|
||||
while True:
|
||||
line = res.stdout.readline().decode('ascii')
|
||||
|
||||
line_len = len(line.split())
|
||||
if not line_len or line.split()[-1] == 'error':
|
||||
break
|
||||
|
||||
ttys_n = "/dev/ttyS{}".format(s_inc)
|
||||
tty_used_list.append(ttys_n)
|
||||
break
|
||||
|
||||
return tty_used_list
|
||||
|
||||
|
||||
def irq2bdf(irq_n):
|
||||
cmd = 'lspci -vv'
|
||||
res = parser_lib.cmd_execute(cmd)
|
||||
bdf = ''
|
||||
irq = 0
|
||||
while True:
|
||||
line = res.stdout.readline().decode('ascii')
|
||||
if not line:
|
||||
break
|
||||
|
||||
if ':' not in line:
|
||||
continue
|
||||
|
||||
if '.' in line.split()[0]:
|
||||
bdf = line.split()[0]
|
||||
|
||||
if "Interrupt:" in line.strip():
|
||||
irq = line.split()[-1]
|
||||
if irq == irq_n and bdf:
|
||||
break
|
||||
|
||||
return bdf
|
||||
|
||||
|
||||
def dump_ttys_info(ttys_list, config):
|
||||
for ttys in ttys_list:
|
||||
ttys_n = ttys.split('/')[-1]
|
||||
type_path = '{}{}/io_type'.format(TTY_PATH, ttys_n)
|
||||
serial_type = read_ttys_node(type_path)
|
||||
|
||||
irq_path = '{}{}/irq'.format(TTY_PATH, ttys_n)
|
||||
irq = read_ttys_node(irq_path)
|
||||
|
||||
if ttys_type[serial_type] == 'PORT':
|
||||
base_path = '{}{}/port'.format(TTY_PATH, ttys_n)
|
||||
elif ttys_type[serial_type] == 'MMIO':
|
||||
base_path = '{}{}/iomem_base'.format(TTY_PATH, ttys_n)
|
||||
|
||||
base = read_ttys_node(base_path)
|
||||
|
||||
ttys_irqs.append(irq)
|
||||
bdf = irq2bdf(irq)
|
||||
print("\tBDF:({}) seri:{} base:{} irq:{}".format(bdf, ttys, base, irq), file=config)
|
||||
|
||||
|
||||
def dump_ttys(config):
|
||||
"""This will get systemd ram which are usable
|
||||
:param config: file pointer that opened for writing board config information
|
||||
"""
|
||||
print("\t<TTYS_INFO>", file=config)
|
||||
ttys_list = detected_ttys()
|
||||
|
||||
dump_ttys_info(ttys_list, config)
|
||||
|
||||
print("\t</TTYS_INFO>", file=config)
|
||||
print("", file=config)
|
||||
|
||||
|
||||
def dump_free_irqs(config):
|
||||
irq_list = ['3', '4', '5', '6', '7', '8', '10', '11', '12', '13', '14', '15']
|
||||
for tty_irq in ttys_irqs:
|
||||
if tty_irq in irq_list:
|
||||
irq_list.remove(tty_irq)
|
||||
|
||||
print("\t<AVAILABLE_IRQ_INFO>", file=config)
|
||||
with open(SYS_IRQ_PATH, 'rt') as irq_config:
|
||||
|
||||
while True:
|
||||
line = irq_config.readline().strip()
|
||||
if ':' not in line:
|
||||
continue
|
||||
|
||||
irq_num = line.split(':')[0]
|
||||
if not line or int(irq_num) >= 16:
|
||||
break
|
||||
|
||||
if irq_num in irq_list:
|
||||
irq_list.remove(irq_num)
|
||||
|
||||
i_cnt = 0
|
||||
print("\t", end="", file=config)
|
||||
for irq in irq_list:
|
||||
i_cnt += 1
|
||||
|
||||
if i_cnt == len(irq_list):
|
||||
print("{}".format(irq), file=config)
|
||||
else:
|
||||
print("{}, ".format(irq), end="", file=config)
|
||||
|
||||
print("\t</AVAILABLE_IRQ_INFO>", file=config)
|
||||
print("", file=config)
|
||||
|
||||
|
||||
def dump_system_ram(config):
|
||||
"""This will get systemd ram which are usable
|
||||
:param config: file pointer that opened for writing board config information
|
||||
"""
|
||||
print("\t<SYSTEM_RAM_INFO>", file=config)
|
||||
with open(IO_MEM_PATH, 'rt') as mem_info:
|
||||
with open(MEM_PATH[0], 'rt') as mem_info:
|
||||
|
||||
while True:
|
||||
line = mem_info.readline().strip()
|
||||
@@ -28,7 +160,7 @@ def get_system_ram(config):
|
||||
print("", file=config)
|
||||
|
||||
|
||||
def get_root_dev(config):
|
||||
def dump_root_dev(config):
|
||||
"""This will get available root device
|
||||
:param config: file pointer that opened for writing board config information
|
||||
"""
|
||||
@@ -38,13 +170,72 @@ def get_root_dev(config):
|
||||
print("", file=config)
|
||||
|
||||
|
||||
|
||||
def dump_total_mem(config):
|
||||
|
||||
total_mem = 0
|
||||
print("\t<TOTAL_MEM_INFO>", file=config)
|
||||
with open(MEM_PATH[1], 'rt') as mem_info:
|
||||
while True:
|
||||
line = mem_info.readline().strip()
|
||||
|
||||
if not line:
|
||||
break
|
||||
|
||||
if ':' in line and line.split(':')[0].strip() == "MemTotal":
|
||||
total_mem = line.split(':')[1]
|
||||
print("\t{}".format(total_mem.strip()), file=config)
|
||||
|
||||
print("\t</TOTAL_MEM_INFO>", file=config)
|
||||
print("", file=config)
|
||||
|
||||
|
||||
def dump_cpu_core_info(config):
|
||||
|
||||
print("\t<CPU_PROCESSOR_INFO>", file=config)
|
||||
processor_id_list = []
|
||||
with open(CPU_INFO_PATH, 'rt') as cpu_info:
|
||||
while True:
|
||||
line = cpu_info.readline()
|
||||
|
||||
if not line:
|
||||
break
|
||||
|
||||
if ':' in line and line.split(':')[0].strip() == "processor":
|
||||
processor_id = line.split(':')[1].strip()
|
||||
processor_id_list.append(processor_id)
|
||||
|
||||
processor_len = len(processor_id_list)
|
||||
for processor_id in processor_id_list:
|
||||
if int(processor_id) == 0:
|
||||
if processor_len == 1:
|
||||
print("\t{},".format(processor_id.strip()), file=config)
|
||||
else:
|
||||
print("\t{},".format(processor_id.strip()), end="", file=config)
|
||||
else:
|
||||
if processor_len == int(processor_id) + 1:
|
||||
print(" {}".format(processor_id.strip()), file=config)
|
||||
else:
|
||||
print(" {},".format(processor_id.strip()), end="", file=config)
|
||||
|
||||
print("\t</CPU_PROCESSOR_INFO>", file=config)
|
||||
print("", file=config)
|
||||
|
||||
|
||||
def generate_info(board_info):
|
||||
"""Get System Ram information
|
||||
:param board_info: this is the file which stores the hardware board information
|
||||
"""
|
||||
with open(board_info, 'a+') as config:
|
||||
|
||||
get_system_ram(config)
|
||||
dump_system_ram(config)
|
||||
|
||||
get_root_dev(config)
|
||||
dump_root_dev(config)
|
||||
|
||||
dump_ttys(config)
|
||||
|
||||
dump_free_irqs(config)
|
||||
|
||||
dump_total_mem(config)
|
||||
|
||||
dump_cpu_core_info(config)
|
||||
|
Reference in New Issue
Block a user