mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2026-06-06 17:21:22 +00:00
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>
273 lines
12 KiB
Python
273 lines
12 KiB
Python
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
#
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
#
|
|
|
|
import scenario_cfg_lib
|
|
|
|
VM_HEADER_DEFINE = scenario_cfg_lib.HEADER_LICENSE + r"""
|
|
#ifndef VM_CONFIGURATIONS_H
|
|
#define VM_CONFIGURATIONS_H
|
|
"""
|
|
VM_END_DEFINE = r"""#endif /* VM_CONFIGURATIONS_H */"""
|
|
|
|
|
|
def gen_common_header(config):
|
|
"""
|
|
This is common header for vm_configuration.h
|
|
:param config: it is the pointer which file write to
|
|
:return: None
|
|
"""
|
|
print("{0}".format(VM_HEADER_DEFINE), file=config)
|
|
|
|
|
|
def gen_sdc_header(config):
|
|
"""
|
|
Generate vm_configuration.h of sdc scenario
|
|
:param config: it is the pointer which file write to
|
|
:return: None
|
|
"""
|
|
gen_common_header(config)
|
|
print("#include <misc_cfg.h>\n", file=config)
|
|
print("#define CONFIG_MAX_VM_NUM\t\t({0}U + CONFIG_MAX_KATA_VM_NUM)".format(
|
|
scenario_cfg_lib.VM_COUNT - 1), file=config)
|
|
print("", file=config)
|
|
print("/* Bits mask of guest flags that can be programmed by device model." +
|
|
" Other bits are set by hypervisor only */", file=config)
|
|
print("#define DM_OWNED_GUEST_FLAG_MASK\t" +
|
|
"(GUEST_FLAG_SECURE_WORLD_ENABLED | GUEST_FLAG_LAPIC_PASSTHROUGH | \\\n" +
|
|
"\t\t\t\t\t\tGUEST_FLAG_RT | GUEST_FLAG_IO_COMPLETION_POLLING)", file=config)
|
|
|
|
print("", file=config)
|
|
print("#define SOS_VM_BOOTARGS\t\t\tSOS_ROOTFS\t\\", file=config)
|
|
print('\t\t\t\t\t"rw rootwait "\t\\', file=config)
|
|
print('\t\t\t\t\t"console=tty0 " \\', file=config)
|
|
print("\t\t\t\t\tSOS_CONSOLE\t\\", file=config)
|
|
print('\t\t\t\t\t"consoleblank=0 "\t\\', file=config)
|
|
print('\t\t\t\t\t"no_timer_check "\t\\', file=config)
|
|
print('\t\t\t\t\t"quiet loglevel=3 "\t\\', file=config)
|
|
print('\t\t\t\t\t"i915.nuclear_pageflip=1 " \\', file=config)
|
|
print('\t\t\t\t\t"i915.avail_planes_per_pipe=0x01010F "\t\\', file=config)
|
|
print('\t\t\t\t\t"i915.domain_plane_owners=0x011111110000 " \\', file=config)
|
|
print('\t\t\t\t\t"i915.enable_gvt=1 "\t\\', file=config)
|
|
print("\t\t\t\t\tSOS_BOOTARGS_DIFF", file=config)
|
|
|
|
print("", file=config)
|
|
print("{0}".format(VM_END_DEFINE), file=config)
|
|
|
|
|
|
def gen_sdc2_header(config):
|
|
"""
|
|
Generate vm_configuration.h of sdc2 scenario
|
|
:param config: it is the pointer which file write to
|
|
:return: None
|
|
"""
|
|
gen_common_header(config)
|
|
print("#include <misc_cfg.h>\n", file=config)
|
|
print("#define CONFIG_MAX_VM_NUM\t\t({0}U + CONFIG_MAX_KATA_VM_NUM)".format(
|
|
scenario_cfg_lib.VM_COUNT), file=config)
|
|
print("", file=config)
|
|
print("/* Bits mask of guest flags that can be programmed by device model." +
|
|
" Other bits are set by hypervisor only */", file=config)
|
|
print("#define DM_OWNED_GUEST_FLAG_MASK\t" +
|
|
"(GUEST_FLAG_SECURE_WORLD_ENABLED | GUEST_FLAG_LAPIC_PASSTHROUGH | \\\n" +
|
|
"\t\t\t\t\t\tGUEST_FLAG_RT | GUEST_FLAG_IO_COMPLETION_POLLING)", file=config)
|
|
|
|
print("", file=config)
|
|
print("#define SOS_VM_BOOTARGS\t\t\tSOS_ROOTFS\t\\", file=config)
|
|
print('\t\t\t\t\t"rw rootwait "\t\\', file=config)
|
|
print('\t\t\t\t\t"console=tty0 " \\', file=config)
|
|
print("\t\t\t\t\tSOS_CONSOLE\t\\", file=config)
|
|
print('\t\t\t\t\t"consoleblank=0 "\t\\', file=config)
|
|
print('\t\t\t\t\t"no_timer_check "\t\\', file=config)
|
|
print('\t\t\t\t\t"quiet loglevel=3 "\t\\', file=config)
|
|
print('\t\t\t\t\t"i915.nuclear_pageflip=1 " \\', file=config)
|
|
print('\t\t\t\t\t"i915.avail_planes_per_pipe=0x01010F "\t\\', file=config)
|
|
print('\t\t\t\t\t"i915.domain_plane_owners=0x011111110000 " \\', file=config)
|
|
print('\t\t\t\t\t"i915.enable_gvt=1 "\t\\', file=config)
|
|
print("\t\t\t\t\tSOS_BOOTARGS_DIFF", file=config)
|
|
|
|
print("", file=config)
|
|
print("{0}".format(VM_END_DEFINE), file=config)
|
|
|
|
|
|
def logic_max_vm_num(config):
|
|
"""
|
|
This is logical max vm number comment
|
|
:param config: it is the pointer which file write to
|
|
:return: None
|
|
"""
|
|
print("", file=config)
|
|
print("#define CONFIG_MAX_VM_NUM\t{0}U".format(scenario_cfg_lib.VM_COUNT), file=config)
|
|
print("", file=config)
|
|
print("/* The VM CONFIGs like:", file=config)
|
|
print(" *\tVMX_CONFIG_PCPU_BITMAP", file=config)
|
|
print(" *\tVMX_CONFIG_MEM_START_HPA", file=config)
|
|
print(" *\tVMX_CONFIG_MEM_SIZE", file=config)
|
|
print(" *\tVMX_CONFIG_OS_BOOTARG_ROOT", file=config)
|
|
print(" *\tVMX_CONFIG_OS_BOOTARG_MAX_CPUS", file=config)
|
|
print(" *\tVMX_CONFIG_OS_BOOTARG_CONSOLE", file=config)
|
|
print(" * might be different on your board, please modify them per your needs.", file=config)
|
|
print(" */", file=config)
|
|
print("", file=config)
|
|
|
|
|
|
def gen_logic_header(vm_info, config):
|
|
"""
|
|
Generate vm_configuration.h of logical_partition scenario
|
|
:param config: it is the pointer which file write to
|
|
:return: None
|
|
"""
|
|
scenario_cfg_lib.vms_count = scenario_cfg_lib.VM_COUNT
|
|
gen_common_header(config)
|
|
# map all the needed pci sub class
|
|
print("#include <pci_devices.h>", file=config)
|
|
print("#include <misc_cfg.h>", file=config)
|
|
print("", file=config)
|
|
print("/* Bits mask of guest flags that can be programmed by device model." +
|
|
" Other bits are set by hypervisor only */", file=config)
|
|
print("#define DM_OWNED_GUEST_FLAG_MASK\t0UL", file=config)
|
|
|
|
logic_max_vm_num(config)
|
|
|
|
for i in range(scenario_cfg_lib.VM_COUNT):
|
|
|
|
cpu_bits = vm_info.get_cpu_bitmap(i)
|
|
print("#define VM{0}_CONFIG_PCPU_BITMAP\t\t\t{1}".format(
|
|
i, cpu_bits['cpu_map']), file=config)
|
|
print("#define VM{0}_CONFIG_MEM_START_HPA\t\t{1}UL".format(
|
|
i, vm_info.mem_info.mem_start_hpa[i]), file=config)
|
|
print("#define VM{0}_CONFIG_MEM_SIZE\t\t\t{1}UL".format(
|
|
i, vm_info.mem_info.mem_size[0]), file=config)
|
|
print('#define VM{0}_CONFIG_OS_BOOTARG_ROOT\t\t"root={1} "'.format(
|
|
i, vm_info.os_cfg.kern_root_dev[i]), file=config)
|
|
print('#define VM{0}_CONFIG_OS_BOOTARG_MAXCPUS\t\t"maxcpus={1} "'.format(
|
|
i, cpu_bits['cpu_num']), file=config)
|
|
print('#define VM{0}_CONFIG_OS_BOOTARG_CONSOLE\t\t"console={1} "'.format(
|
|
i, vm_info.os_cfg.kern_console[i]), file=config)
|
|
print("", file=config)
|
|
|
|
print('/* VM pass-through devices assign policy:', file=config)
|
|
print(' * VM0: one Mass Storage controller, one Network controller;', file=config)
|
|
print(' * VM1: one Mass Storage controller, one Network controller' +
|
|
'(if a secondary Network controller class device exist);', file=config)
|
|
print(' */', file=config)
|
|
print('#define VM0_STORAGE_CONTROLLER\t\t\tSATA_CONTROLLER_0', file=config)
|
|
print('#define VM0_NETWORK_CONTROLLER\t\t\tETHERNET_CONTROLLER_0', file=config)
|
|
print('#define VM0_CONFIG_PCI_DEV_NUM\t\t\t3U', file=config)
|
|
print('', file=config)
|
|
print('#define VM1_STORAGE_CONTROLLER\t\t\tUSB_CONTROLLER_0', file=config)
|
|
print('#if defined(ETHERNET_CONTROLLER_1)', file=config)
|
|
print('/* if a secondary Ethernet controller subclass exist, assign to VM1 */', file=config)
|
|
print('#define VM1_NETWORK_CONTROLLER\t\t\tETHERNET_CONTROLLER_1', file=config)
|
|
print('#elif defined(NETWORK_CONTROLLER_0)', file=config)
|
|
print('/* if a Network controller subclass exist' +
|
|
'(usually it is a wireless network card), assign to VM1 */', file=config)
|
|
print('#define VM1_NETWORK_CONTROLLER\t\t\tNETWORK_CONTROLLER_0', file=config)
|
|
print('#endif', file=config)
|
|
print('', file=config)
|
|
print('#if defined(VM1_NETWORK_CONTROLLER)', file=config)
|
|
print('#define VM1_CONFIG_PCI_DEV_NUM\t\t\t3U', file=config)
|
|
print('#else', file=config)
|
|
print('/* no network controller could be assigned to VM1 */', file=config)
|
|
print('#define VM1_CONFIG_PCI_DEV_NUM\t\t\t2U', file=config)
|
|
print('#endif', file=config)
|
|
print("", file=config)
|
|
print("{0}".format(VM_END_DEFINE), file=config)
|
|
|
|
|
|
def gen_industry_header(config):
|
|
"""
|
|
Generate vm_configuration.h of industry scenario
|
|
:param config: it is the pointer which file write to
|
|
:return: None
|
|
"""
|
|
gen_common_header(config)
|
|
print("#include <misc_cfg.h>", file=config)
|
|
print("", file=config)
|
|
print("#define CONFIG_MAX_VM_NUM\t\t({0}U + CONFIG_MAX_KATA_VM_NUM)".format(
|
|
scenario_cfg_lib.VM_COUNT), file=config)
|
|
print("", file=config)
|
|
print("/* Bits mask of guest flags that can be programmed by device model." +
|
|
" Other bits are set by hypervisor only */", file=config)
|
|
print("#define DM_OWNED_GUEST_FLAG_MASK\t(GUEST_FLAG_SECURE_WORLD_ENABLED | " +
|
|
"GUEST_FLAG_LAPIC_PASSTHROUGH | \\", file=config)
|
|
print("\t\t\t\t\t\tGUEST_FLAG_RT | GUEST_FLAG_IO_COMPLETION_POLLING)", file=config)
|
|
print("", file=config)
|
|
print("#define SOS_VM_BOOTARGS\t\t\tSOS_ROOTFS\t\\", file=config)
|
|
print('\t\t\t\t\t"rw rootwait "\t\\', file=config)
|
|
print('\t\t\t\t\t"console=tty0 "\t\\', file=config)
|
|
print("\t\t\t\t\tSOS_CONSOLE\t\\", file=config)
|
|
print('\t\t\t\t\t"consoleblank=0\t"\t\\', file=config)
|
|
print('\t\t\t\t\t"no_timer_check "\t\\', file=config)
|
|
print('\t\t\t\t\t"quiet loglevel=3 "\t\\', file=config)
|
|
print('\t\t\t\t\t"i915.nuclear_pageflip=1 " \\', file=config)
|
|
print('\t\t\t\t\t"i915.avail_planes_per_pipe=0x01010F "\t\\', file=config)
|
|
print('\t\t\t\t\t"i915.domain_plane_owners=0x011111110000 " \\', file=config)
|
|
print('\t\t\t\t\t"i915.enable_gvt=1 "\t\\', file=config)
|
|
print("\t\t\t\t\tSOS_BOOTARGS_DIFF", file=config)
|
|
print("", file=config)
|
|
print("{0}".format(VM_END_DEFINE), file=config)
|
|
|
|
|
|
def gen_hybrid_header(vm_info, config):
|
|
"""
|
|
Generate vm_configuration.h of hybrid scenario
|
|
:param vm_info: it is the class which contain all user setting information
|
|
:param config: it is the pointer which file write to
|
|
:return: None
|
|
"""
|
|
gen_common_header(config)
|
|
print("#include <misc_cfg.h>\n", file=config)
|
|
print("/* Bits mask of guest flags that can be programmed by device model." +
|
|
" Other bits are set by hypervisor only */", file=config)
|
|
print("#define DM_OWNED_GUEST_FLAG_MASK\t" +
|
|
"(GUEST_FLAG_SECURE_WORLD_ENABLED | GUEST_FLAG_LAPIC_PASSTHROUGH | \\\n" +
|
|
"\t\t\t\t\t\tGUEST_FLAG_RT | GUEST_FLAG_IO_COMPLETION_POLLING)", file=config)
|
|
|
|
cpu_bits = vm_info.get_cpu_bitmap(0)
|
|
print("", file=config)
|
|
print("#define CONFIG_MAX_VM_NUM\t\t({0}U + CONFIG_MAX_KATA_VM_NUM)".format(
|
|
scenario_cfg_lib.VM_COUNT), file=config)
|
|
print("", file=config)
|
|
print("#define VM0_CONFIG_PCPU_BITMAP\t\t{0}".format(cpu_bits['cpu_map']), file=config)
|
|
print("#define VM0_CONFIG_MEM_START_HPA\t{0}UL".format(
|
|
vm_info.mem_info.mem_start_hpa[0]), file=config)
|
|
print("#define VM0_CONFIG_MEM_SIZE\t\t{0}UL".format(vm_info.mem_info.mem_size[0]), file=config)
|
|
print("", file=config)
|
|
print("#define SOS_VM_BOOTARGS\t\t\tSOS_ROOTFS\t\\", file=config)
|
|
print('\t\t\t\t\t"rw rootwait "\t\\', file=config)
|
|
print('\t\t\t\t\t"console=tty0 " \\', file=config)
|
|
print("\t\t\t\t\tSOS_CONSOLE\t\\", file=config)
|
|
print('\t\t\t\t\t"consoleblank=0 "\t\\', file=config)
|
|
print('\t\t\t\t\t"no_timer_check "\t\\', file=config)
|
|
print('\t\t\t\t\t"quiet loglevel=3 "\t\\', file=config)
|
|
print('\t\t\t\t\t"i915.nuclear_pageflip=1 " \\', file=config)
|
|
print('\t\t\t\t\t"i915.avail_planes_per_pipe=0x01010F "\t\\', file=config)
|
|
print('\t\t\t\t\t"i915.domain_plane_owners=0x011111110000 " \\', file=config)
|
|
print('\t\t\t\t\t"i915.enable_gvt=1 "\t\\', file=config)
|
|
print("\t\t\t\t\tSOS_BOOTARGS_DIFF", file=config)
|
|
|
|
print("", file=config)
|
|
print("{0}".format(VM_END_DEFINE), file=config)
|
|
|
|
|
|
def generate_file(scenario, vm_info, config):
|
|
"""
|
|
Start to generate vm_configurations.h
|
|
:param scenario: it is scenario name
|
|
:param vm_info: it is the class which contain all user setting information
|
|
:param config: it is a file pointer of board information for writing to
|
|
"""
|
|
if scenario == 'sdc':
|
|
gen_sdc_header(config)
|
|
elif scenario == 'sdc2':
|
|
gen_sdc2_header(config)
|
|
elif scenario == 'logical_partition':
|
|
gen_logic_header(vm_info, config)
|
|
elif scenario == 'industry':
|
|
gen_industry_header(config)
|
|
else:
|
|
# scenario is 'hybrid'
|
|
gen_hybrid_header(vm_info, config)
|