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:
Wei Liu
2019-09-05 13:31:11 +08:00
committed by wenlingz
parent b73f97aaba
commit 28d1b909e6
21 changed files with 3909 additions and 276 deletions

View File

@@ -14,24 +14,26 @@ PLATFORM_HEADER = r"""/* DO NOT MODIFY THIS FILE UNLESS YOU KNOW WHAT YOU ARE DO
PLATFORM_END_HEADER = "\n#endif /* PLATFORM_ACPI_INFO_H */"
class OverridAccessSize():
"""The Pm access size which are needed to redefine"""
""" The Pm access size which are needed to redefine """
def __init__(self):
self.pm1a_cnt_ac_sz = True
self.pm1b_cnt_ac_sz = True
self.pm1b_evt_ac_sz = True
def style_check_1(self):
"""Style check if have public method"""
""" Style check if have public method """
self.pm1a_cnt_ac_sz = True
def style_check_2(self):
"""Style check if have public method"""
""" Style check if have public method """
self.pm1a_cnt_ac_sz = True
def multi_parser(line, s_line, pm_ac_sz, config):
"""Multi parser the line
"""
Multi parse the line
:param line: it is a line read from default_acpi_info.h
:param s_line: it is a line read from board information file
:param pm_ac_sz: it is a class for access size which would be override
@@ -76,7 +78,8 @@ def multi_parser(line, s_line, pm_ac_sz, config):
def multi_info_parser(config, default_platform, msg_s, msg_e):
"""Parser multi information
"""
Parse multi information
:param config: it is a file pointer to write acpi information
:param default_platform: it is the default_acpi_info.h in acrn-hypervisor
:param msg_s: it is a pattern of key stings what start to match from board information
@@ -109,7 +112,8 @@ def multi_info_parser(config, default_platform, msg_s, msg_e):
def write_direct_info_parser(config, msg_s, msg_e):
"""Direct to write
"""
Direct to write
:param config: it is a file pointer to write acpi information
: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
@@ -123,7 +127,8 @@ def write_direct_info_parser(config, msg_s, msg_e):
def drhd_info_parser(config):
"""Parser DRHD information
"""
Parse DRHD information
:param config: it is a file pointer to write acpi information
"""
prev_num = 0
@@ -149,7 +154,8 @@ def drhd_info_parser(config):
def platform_info_parser(config, default_platform):
"""Parser ACPI information
"""
Parse ACPI information
:param config: it is a file pointer to write acpi information
:param default_platform: it is the default_acpi_info.h in acrn-hypervisor
"""
@@ -165,7 +171,8 @@ def platform_info_parser(config, default_platform):
def generate_file(config, default_platform):
"""write board_name_acpi_info.h
"""
write board_name_acpi_info.h
:param config: it is a file pointer to write acpi information
:param default_platform: it is the default_acpi_info.h in acrn-hypervisor
"""
@@ -174,7 +181,7 @@ def generate_file(config, default_platform):
print("{}".format(PLATFORM_HEADER), file=config)
board_cfg_lib.handle_bios_info(config)
# parser for the platform info
# parse for the platform info
platform_info_parser(config, default_platform)
print("{}".format(PLATFORM_END_HEADER), file=config)

View File

@@ -7,32 +7,17 @@ import sys
import board_cfg_lib
def clos_info_parser():
"""Parser CLOS information"""
cache_support = False
clos_max = 0
cat_lines = board_cfg_lib.get_info(
board_cfg_lib.BOARD_INFO_FILE, "<CLOS_INFO>", "</CLOS_INFO>")
for line in cat_lines:
if line.split(':')[0] == "clos supported by cache":
cache_support = line.split(':')[1].strip()
elif line.split(':')[0] == "clos max":
clos_max = int(line.split(':')[1])
return (cache_support, clos_max)
def gen_cat(config):
"""Get CAT information
"""
Get CAT information
:param config: it is a file pointer of board information for writing to
"""
(cache_support, clos_max) = clos_info_parser()
err_dic = {}
(cache_support, clos_max) = board_cfg_lib.clos_info_parser(board_cfg_lib.BOARD_INFO_FILE)
print("\n#include <board.h>", file=config)
print("#include <acrn_common.h>", file=config)
print("#include <msr.h>", file=config)
if cache_support == "False" or clos_max == 0:
print("\nstruct platform_clos_info platform_clos_array[0];", file=config)
@@ -50,9 +35,8 @@ def gen_cat(config):
elif cache_support == "L3":
print("\t\t.msr_index = {0}U,".format(hex(0x00000C90+i_cnt)), file=config)
else:
board_cfg_lib.print_red("The input of {} was corrupted!".format(
board_cfg_lib.BOARD_INFO_FILE))
sys.exit(1)
err_dic['board config: generate board.c failed'] = "The input of {} was corrupted!".format(board_cfg_lib.BOARD_INFO_FILE)
return err_dic
print("\t},", file=config)
print("};\n", file=config)
@@ -61,10 +45,12 @@ def gen_cat(config):
file=config)
print("", file=config)
return err_dic
def gen_px_cx(config):
"""Get Px/Cx and store them to board.c
"""
Get Px/Cx and store them to board.c
:param config: it is a file pointer of board information for writing to
"""
cpu_brand_lines = board_cfg_lib.get_info(
@@ -97,16 +83,22 @@ def gen_px_cx(config):
def generate_file(config):
"""Start to generate board.c
"""
Start to generate board.c
:param config: it is a file pointer of board information for writing to
"""
err_dic = {}
print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
# insert bios info into board.c
board_cfg_lib.handle_bios_info(config)
# start to parser to get CAT info
gen_cat(config)
err_dic = gen_cat(config)
if err_dic:
return err_dic
# start to parser PX/CX info
gen_px_cx(config)
return err_dic

View File

@@ -6,79 +6,53 @@
import os
import sys
import shutil
import subprocess
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'library'))
import board_cfg_lib
import board_c
import pci_devices_h
import acpi_platform_h
import misc_cfg_h
import ve820_c
import new_board_kconfig
ACRN_PATH = "../../../"
ACRN_PATH = board_cfg_lib.SOURCE_ROOT_DIR
ACRN_CONFIG = ACRN_PATH + "hypervisor/arch/x86/configs/"
BOARD_NAMES = ['apl-mrb', 'apl-nuc', 'apl-up2', 'dnv-cb2', 'nuc6cayh',
'nuc7i7dnb', 'kbl-nuc-i7', 'icl-rvp']
ACRN_DEFAULT_PLATFORM = ACRN_PATH + "hypervisor/include/arch/x86/default_acpi_info.h"
GEN_FILE = ["vm_configurations.h", "vm_configurations.c", "pt_dev.c", "pci_devices.h",
"board.c", "_acpi_info.h"]
PY_CACHES = ["__pycache__", "board_config/__pycache__"]
BIN_LIST = ['git']
GEN_FILE = ["pci_devices.h", "board.c", "_acpi_info.h", "misc_cfg.h", "ve820.c", ".config"]
def prepare():
"""Prepare to check the environment"""
for excute in BIN_LIST:
res = subprocess.Popen("which {}".format(excute), shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
line = res.stdout.readline().decode('ascii')
if not line:
board_cfg_lib.print_yel("'{}' not found, please install it!".format(excute))
sys.exit(1)
if excute == "git":
res = subprocess.Popen("git tag -l", shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
line = res.stdout.readline().decode("ascii")
if "acrn" not in line:
board_cfg_lib.print_red("Run this tool in acrn-hypervisor mainline source code!")
sys.exit(1)
for py_cache in PY_CACHES:
if os.path.exists(py_cache):
shutil.rmtree(py_cache)
def gen_patch(srcs_list, board_name):
"""Generate patch and apply to local source code
:param srcs_list: it is a list what contains source files
:param board_name: board name
def main(args):
"""
changes = ' '.join(srcs_list)
git_add = "git add {}".format(changes)
subprocess.call(git_add, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
# commit this changes
git_commit = 'git commit -sm "acrn-config: config board patch for {}"'.format(board_name)
subprocess.call(git_commit, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
def main(board_info_file):
"""This is main function to start generate source code related with board
:param board_info_file: it is a file what contains board information for script to read from
This is main function to start generate source code related with board
:param args: it is a command line args for the script
"""
board = ''
err_dic = {}
config_srcs = []
config_dirs = []
(err_dic, board_info_file, scenario_info_file) = board_cfg_lib.get_param(args)
if err_dic:
return err_dic
board_cfg_lib.BOARD_INFO_FILE = board_info_file
board_cfg_lib.SCENARIO_INFO_FILE = scenario_info_file
board_cfg_lib.get_vm_count(scenario_info_file)
# get board name
board = board_cfg_lib.get_board_name(board_info_file)
(err_dic, board) = board_cfg_lib.get_board_name()
if err_dic:
return err_dic
board_cfg_lib.BOARD_NAME = board
# check if this is the scenario config which matched board info
(err_dic, status) = board_cfg_lib.is_config_file_match()
if not status:
err_dic['board config: Not match'] = "The board xml and scenario xml should be matched"
return err_dic
config_dirs.append(ACRN_CONFIG + board)
if board not in BOARD_NAMES:
@@ -86,17 +60,25 @@ def main(board_info_file):
if not os.path.exists(config_dir):
os.makedirs(config_dir)
config_pci = config_dirs[0] + '/' + GEN_FILE[3]
config_board = config_dirs[0] + '/' + GEN_FILE[4]
config_platform = config_dirs[0] + '/' + board + GEN_FILE[5]
config_pci = config_dirs[0] + '/' + GEN_FILE[0]
config_board = config_dirs[0] + '/' + GEN_FILE[1]
config_platform = config_dirs[0] + '/' + board + GEN_FILE[2]
config_misc_cfg = config_dirs[0] + '/' + GEN_FILE[3]
config_ve820 = config_dirs[0] + '/' + GEN_FILE[4]
config_board_kconfig = ACRN_CONFIG + board + GEN_FILE[5]
config_srcs.append(config_pci)
config_srcs.append(config_board)
config_srcs.append(config_platform)
config_srcs.append(config_misc_cfg)
config_srcs.append(config_ve820)
config_srcs.append(config_board_kconfig)
# generate board.c
with open(config_board, 'w+') as config:
board_c.generate_file(config)
err_dic = board_c.generate_file(config)
if err_dic:
return err_dic
# generate pci_devices.h
with open(config_pci, 'w+') as config:
@@ -106,36 +88,61 @@ def main(board_info_file):
with open(config_platform, 'w+') as config:
acpi_platform_h.generate_file(config, ACRN_DEFAULT_PLATFORM)
# move changes to patch, and apply to the source code
gen_patch(config_srcs, board)
# generate acpi_platform.h
with open(config_ve820, 'w+') as config:
err_dic = ve820_c.generate_file(config)
if err_dic:
return err_dic
# generate acpi_platform.h
with open(config_misc_cfg, 'w+') as config:
err_dic = misc_cfg_h.generate_file(config)
if err_dic:
return err_dic
# generate new board_name.config
if board not in BOARD_NAMES:
with open(config_board_kconfig, 'w+') as config:
err_dic = new_board_kconfig.generate_file(config)
if err_dic:
return err_dic
# move changes to patch, and apply to the source code
err_dic = board_cfg_lib.gen_patch(config_srcs, board)
if board not in BOARD_NAMES and not err_dic:
print("Config patch for NEW board {} is committed successfully!".format(board))
else:
elif not err_dic:
print("Config patch for {} is committed successfully!".format(board))
else:
print("Config patch for {} is failed".format(board))
return err_dic
def usage():
"""This is usage for how to use this tool"""
print("usage= [h] --board <board_info_file>'")
print('board_info_file, : file name of the board info"')
sys.exit(1)
def ui_entry_api(board_info,scenario_info):
arg_list = ['board_cfg_gen.py', '--board', board_info, '--scenario', scenario_info]
err_dic = board_cfg_lib.prepare()
if err_dic:
return err_dic
err_dic = main(arg_list)
return err_dic
if __name__ == '__main__':
prepare()
ARGS = sys.argv[1:]
if ARGS[0] != '--board':
usage()
err_dic = board_cfg_lib.prepare()
if err_dic:
for err_k, err_v in err_dic.items():
board_cfg_lib.print_red("{}: {}".format(err_k, err_v), err=True)
sys.exit(1)
BOARD_INFO_FILE = ARGS[1]
if not os.path.exists(BOARD_INFO_FILE):
board_cfg_lib.print_red("{} is not exist!".format(BOARD_INFO_FILE))
sys.exit(1)
board_cfg_lib.BOARD_INFO_FILE = BOARD_INFO_FILE
main(BOARD_INFO_FILE)
ARGS = sys.argv
err_dic = main(ARGS)
if err_dic:
for err_k, err_v in err_dic.items():
board_cfg_lib.print_red("{}: {}".format(err_k, err_v), err=True)

View File

@@ -1,138 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import sys
HV_LICENSE_FILE = '../library/hypervisor_license'
BOARD_INFO_FILE = "board_info.txt"
BIOS_INFO = ['BIOS Information', 'Vendor:', 'Version:', 'Release Date:', 'BIOS Revision:']
BASE_BOARD = ['Base Board Information', 'Manufacturer:', 'Product Name:', 'Version:']
def open_license():
"""Get the license"""
with open(HV_LICENSE_FILE, 'r') as f_licence:
license_s = f_licence.read().strip()
return license_s
HEADER_LICENSE = open_license() + "\n"
#LOGICAL_PT_PROFILE = {}
#LOGICAL_PCI_DEV = {}
#LOGICAL_PCI_LINE = {}
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'
"""
if warn:
print("\033[1;33mWarning\033[0m:"+msg)
else:
print("\033[1;33m{0}\033[0m".format(msg))
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'
"""
if err:
print("\033[1;31mError\033[0m:"+msg)
else:
print("\033[1;31m{0}\033[0m".format(msg))
def get_board_name(board_info):
"""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
"""
with open(board_info, 'rt') as f_board:
line = f_board.readline()
if not "board=" in line:
print_red("acrn-config board info xml was corrupted!")
sys.exit(1)
board = line.split('"')[1].strip('"')
return board
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_start = False
info_end = False
info_lines = []
num = len(msg_s.split())
try:
with open(board_info, 'rt') as f_board:
while True:
line = f_board.readline()
if not line:
break
if " ".join(line.split()[0:num]) == msg_s:
info_start = True
info_end = False
continue
if " ".join(line.split()[0:num]) == msg_e:
info_start = False
info_end = True
continue
if info_start and not info_end:
info_lines.append(line)
continue
if not info_start and info_end:
return info_lines
except IOError as err:
print_red(str(err), err=True)
sys.exit(1)
def handle_bios_info(config):
"""Handle bios information
:param config: it is a file pointer of bios information for writing to
"""
bios_lines = get_info(BOARD_INFO_FILE, "<BIOS_INFO>", "</BIOS_INFO>")
board_lines = get_info(BOARD_INFO_FILE, "<BASE_BOARD_INFO>", "</BASE_BOARD_INFO>")
print("/*", file=config)
if not bios_lines or not board_lines:
print(" * DMI info is not found", file=config)
else:
i_cnt = 0
bios_board = BIOS_INFO + BASE_BOARD
# remove the same value and keep origin sort
bios_board_info = list(set(bios_board))
bios_board_info.sort(key=bios_board.index)
bios_board_lines = bios_lines + board_lines
bios_info_len = len(bios_lines)
for line in bios_board_lines:
if i_cnt == bios_info_len:
print(" *", file=config)
i_cnt += 1
for misc_info in bios_board_info:
if misc_info == " ".join(line.split()[0:1]) or misc_info == \
" ".join(line.split()[0:2]) or misc_info == " ".join(line.split()[0:3]):
print(" * {0}".format(line.strip()), file=config)
print(" */", file=config)

View File

@@ -0,0 +1,151 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import board_cfg_lib
MISC_CFG_HEADER = """
#ifndef MISC_CFG_H
#define MISC_CFG_H
"""
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 = []
def sos_bootarg_diff(sos_cmdlines, config):
if sos_cmdlines:
sos_len = len(sos_cmdlines)
i = 0
for sos_cmdline in sos_cmdlines:
if not sos_cmdline:
continue
i += 1
if i == 1:
if sos_len == 1:
print('#define SOS_BOOTARGS_DIFF\t{}'.format(sos_cmdline), file=config)
else:
print('#define SOS_BOOTARGS_DIFF\t"{} " \\'.format(sos_cmdline), file=config)
else:
if i < sos_len:
print('\t\t\t\t"{} "\t\\'.format(sos_cmdline), file=config)
else:
print('\t\t\t\t"{}"'.format(sos_cmdline), file=config)
def parse_boot_info():
err_dic = {}
vm_types = []
(err_dic, scenario_name) = board_cfg_lib.get_scenario_name()
if err_dic:
return (err_dic, sos_cmdlines, sos_rootfs, vuart0_dic, vuart1_dic, vm_types)
if scenario_name != "logical_partition":
sos_cmdlines = board_cfg_lib.get_sub_leaf_tag(board_cfg_lib.SCENARIO_INFO_FILE, "board_private", "bootargs")
sos_rootfs = board_cfg_lib.get_sub_leaf_tag(board_cfg_lib.SCENARIO_INFO_FILE, "board_private", "rootfs")
(err_dic, vuart0_dic, vuart1_dic) = board_cfg_lib.get_board_private_vuart("board_private", "console")
else:
sos_cmdlines = board_cfg_lib.get_sub_leaf_tag(board_cfg_lib.SCENARIO_INFO_FILE, "os_config", "bootargs")
sos_rootfs = board_cfg_lib.get_sub_leaf_tag(board_cfg_lib.SCENARIO_INFO_FILE, "os_config", "rootfs")
(err_dic, vuart0_dic, vuart1_dic) = board_cfg_lib.get_board_private_vuart("os_config", "console")
if err_dic:
return (err_dic, sos_cmdlines, sos_rootfs, vuart0_dic, vuart1_dic, vm_types)
for i in range(board_cfg_lib.VM_COUNT):
vm_type = board_cfg_lib.get_order_type_by_vmid(i)
vm_types.append(vm_type)
return (err_dic, sos_cmdlines, sos_rootfs, vuart0_dic, vuart1_dic, vm_types)
def generate_file(config):
"""
Start to generate board.c
:param config: it is a file pointer of board information for writing to
"""
board_cfg_lib.get_valid_irq(board_cfg_lib.BOARD_INFO_FILE)
# get the vuart0/vuart1 which user chosed from scenario.xml of board_private section
(err_dic, ttys_n) = board_cfg_lib.parser_vuart_console()
if err_dic:
return err_dic
# parse sos_bootargs/rootfs/console
(err_dic, sos_cmdlines, sos_rootfs, vuart0_dic, vuart1_dic, vm_types) = parse_boot_info()
if err_dic:
return err_dic
# parse to get poart/base of vuart0/vuart1
vuart0_port_base = board_cfg_lib.TTY_CONSOLE[list(vuart0_dic.keys())[0]]
vuart0_irq = vuart0_dic[list(vuart0_dic.keys())[0]]
vuart1_port_base = board_cfg_lib.TTY_CONSOLE[list(vuart1_dic.keys())[0]]
vuart1_irq = vuart1_dic[list(vuart1_dic.keys())[0]]
# parse the setting ttys vuatx dic: {vmid:base/irq}
vuart0_setting = Vuart()
vuart1_setting = Vuart()
vuart0_setting = board_cfg_lib.get_vuart_info_id(board_cfg_lib.SCENARIO_INFO_FILE, 0)
vuart1_setting = board_cfg_lib.get_vuart_info_id(board_cfg_lib.SCENARIO_INFO_FILE, 1)
# sos command lines information
sos_cmdlines = [i for i in sos_cmdlines[0].split() if i != '']
# get native rootfs list from board_info.xml
(root_devs, root_dev_num) = board_cfg_lib.get_rootfs(board_cfg_lib.BOARD_INFO_FILE)
# start to generate misc_cfg.h
print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
print("{}".format(MISC_CFG_HEADER), file=config)
# define rootfs with macro
for i in range(root_dev_num):
print('#define ROOTFS_{}\t\t"root={} "'.format(i, root_devs[i]), file=config)
# sos rootfs and console
print("", file=config)
if "SOS_VM" in vm_types:
print('#define SOS_ROOTFS\t\t"root={} "'.format(sos_rootfs[0]), file=config)
print('#define SOS_CONSOLE\t\t"console={} "'.format(ttys_n), file=config)
# sos com base/irq
i_type = 0
for vm_type in vm_types:
if vm_type == "SOS_VM":
break
i_type += 1
if "SOS_VM" in vm_types:
print("#define SOS_COM1_BASE\t\t{}U".format(vuart0_port_base), file=config)
print("#define SOS_COM1_IRQ\t\t{}U".format(vuart0_irq), file=config)
if vuart1_setting[i_type]['base'] != "INVALID_COM_BASE":
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:
sos_bootarg_diff(sos_cmdlines, config)
print("{}".format(MISC_CFG_END), file=config)
return err_dic

View File

@@ -0,0 +1,92 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import sys
import board_cfg_lib
DESC = """
# New board kconfig generated by vm config tool
# Modified by Kconfiglib (https://github.com/ulfalizer/Kconfiglib)
"""
VM_NUM_MAP_TOTAL_HV_RAM_SIZE = {
# 120M
2:'0x7800000',
# 150M
3:'0x9600000',
# 180M
4:'0xB400000',
# 210M
5:'0xD200000',
# 240M
6:'0xF000000',
# 270M
7:'0x10E00000',
}
def get_addr_for_hv(ram_range, hpa_size):
"""
This is get hv address from System RAM as host physical size
:param ram_range: System RAM mapping
:param hpa_size: fixed host physical size
:return: start host physical address
"""
ret_start_addr = 0
tmp_order_key = 0
tmp_order_key = sorted(ram_range)
for start_addr in tmp_order_key:
mem_range = ram_range[start_addr]
if mem_range > int(hpa_size, 16):
ret_start_addr = start_addr
break
return hex(ret_start_addr)
def get_ram_range():
""" Get System RAM range mapping """
# read system ram from board_info.xml
ram_range = {}
sys_mem_lines = board_cfg_lib.get_info(
board_cfg_lib.BOARD_INFO_FILE, "<SYSTEM_RAM_INFO>", "</SYSTEM_RAM_INFO>")
for line in sys_mem_lines:
start_addr = int(line.split('-')[0], 16)
end_addr = int(line.split('-')[1].split(':')[0], 16)
mem_range = end_addr - start_addr
ram_range[start_addr] = mem_range
return ram_range
def generate_file(config):
"""Start to generate board.c
:param config: it is a file pointer of board information for writing to
"""
err_dic = {}
# this dictonary mapped with 'address start':'mem range'
ram_range = {}
if board_cfg_lib.VM_COUNT in list(VM_NUM_MAP_TOTAL_HV_RAM_SIZE.keys()):
hv_ram_size = VM_NUM_MAP_TOTAL_HV_RAM_SIZE[board_cfg_lib.VM_COUNT]
else:
board_cfg_lib.print_red("VM num should not greater than 8", err=True)
err_dic["baord config: total vm number error"] = "VM num should not greater than 8"
return err_dic
ram_range = get_ram_range()
hv_start_addr = get_addr_for_hv(ram_range, hv_ram_size)
print('CONFIG_BOARD="{}"'.format(board_cfg_lib.BOARD_NAME), file=config)
print("{}".format(DESC), file=config)
print("CONFIG_HV_RAM_START={}".format(hv_start_addr), file=config)
print("CONFIG_HV_RAM_SIZE={}".format(hv_ram_size), file=config)
return err_dic

View File

@@ -15,7 +15,7 @@ PCI_END_HEADER = r"""
def parser_pci():
"""Parser PCI lines"""
""" Parse PCI lines """
cur_bdf = 0
prev_bdf = 0
tmp_bar_dic = {}
@@ -42,9 +42,7 @@ def parser_pci():
pci_dev_dic[pci_bdf] = pci_sub_name
cur_bdf = pci_bdf
#board_cfg_lib.LOGICAL_PCI_LINE[pci_bdf] = line
# skipt the first init value
if not prev_bdf:
prev_bdf = cur_bdf
@@ -57,18 +55,29 @@ def parser_pci():
# output all the pci device list to pci_device.h
sub_name_count = collections.Counter(pci_dev_dic.values())
# share the pci profile with pt_dev
#board_cfg_lib.LOGICAL_PT_PROFILE = sub_name_count
#board_cfg_lib.LOGICAL_PCI_DEV = pci_dev_dic
if tmp_bar_dic:
pci_bar_dic[cur_bdf] = tmp_bar_dic
return (pci_dev_dic, pci_bar_dic, sub_name_count)
def undline_name(name):
"""
This convert name which has contain '-' to '_'
:param name: name which contain '-'
:return:
"""
name_list = name
if '-' in name:
name_list = "_".join(name.split('-'))
return name_list
def write_pbdf(i_cnt, bdf, subname, config):
"""Parser and generate pbdf
"""
Parser and generate pbdf
:param i_cnt: the number of pci devices have the same PCI subname
:param bdf: it is a string what contains BDF
:param subname: it is a string belong to PIC subname
@@ -78,7 +87,10 @@ def write_pbdf(i_cnt, bdf, subname, config):
if i_cnt == 0 and subname.upper() == "HOST BRIDGE":
tmp_sub_name = "_".join(subname.split()).upper()
else:
tmp_sub_name = "_".join(subname.split()).upper() + "_" + str(i_cnt)
if '-' in subname:
tmp_sub_name = undline_name(subname)
else:
tmp_sub_name = "_".join(subname.split()).upper() + "_" + str(i_cnt)
bus = int(bdf.split(':')[0], 16)
dev = int(bdf.split(':')[1].split('.')[0], 16)
@@ -89,7 +101,8 @@ def write_pbdf(i_cnt, bdf, subname, config):
def write_vbar(bdf, pci_bar_dic, config):
"""Parser and generate vbar
"""
Parser and generate vbar
:param bdf: it is a string what contains BDF
:param pci_bar_dic: it is a dictionary of pci vbar for those BDF
:param config: it is a file pointer of pci information for writing to
@@ -119,7 +132,8 @@ def write_vbar(bdf, pci_bar_dic, config):
def generate_file(config):
"""Get PCI device and generate pci_devices.h
"""
Get PCI device and generate pci_devices.h
:param config: it is a file pointer of pci information for writing to
"""

View File

@@ -0,0 +1,147 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import sys
import board_cfg_lib
TOTAL_MEM_SIZE = 4 * 1024 * 1024 * 1024
LOW_MEM_TO_PCI_HOLE = 0x20000000
def undline_board_name(board_name):
"""
This convert board name which has contain '-' to '_'
:param board_name:
:return:
"""
name_list = board_name
if '-' in board_name:
name_list = "_".join(board_name.split('-'))
return name_list
def ve820_per_launch(config, hpa_size):
"""
Start to generate board.c
:param config: it is a file pointer of board information for writing to
"""
(err_dic, board_name) = board_cfg_lib.get_board_name()
if err_dic:
return err_dic
board_name = undline_board_name(board_name)
low_mem_to_pci_hole_len = '0xA0000000'
low_mem_to_pci_hole = '0x20000000'
pci_hole_addr = '0xe0000000'
pci_hole_len = '0x20000000'
start_low_hpa = 0x100000
hpa_len = int(hpa_size, 16) - 1 * 1024 * 1024
# pre_launch memroy: mem_size is the ve820 length
print("#include <e820.h>", file=config)
print("#include <vm.h>", file=config)
print("", file=config)
print("#define VE820_ENTRIES_{}\t{}U".format(board_name.upper(), 5), file=config)
print("static const struct e820_entry ve820_entry[{}] = {{".format(
"VE820_ENTRIES_{}".format(board_name.upper())), file=config)
print("\t{\t/* usable RAM under 1MB */", file=config)
print("\t\t.baseaddr = 0x0UL,", file=config)
print("\t\t.length = 0xF0000UL,\t\t/* 960KB */", file=config)
print("\t\t.type = E820_TYPE_RAM", file=config)
print("\t},", file=config)
print("", file=config)
print("\t{\t/* mptable */", file=config)
print("\t\t.baseaddr = 0xF0000UL,\t\t/* 960KB */", file=config)
print("\t\t.length = 0x10000UL,\t\t/* 16KB */", file=config)
print("\t\t.type = E820_TYPE_RESERVED", file=config)
print("\t},", file=config)
print("", file=config)
print("\t{\t/* lowmem */", file=config)
print("\t\t.baseaddr = {}UL,\t\t/* 1MB */".format(
hex(start_low_hpa)), file=config)
print("\t\t.length = {}UL,\t/* {}MB */".format(
hex(hpa_len), hpa_len / 1024 / 1024), file=config)
print("\t\t.type = E820_TYPE_RAM", file=config)
print("\t},", file=config)
print("", file=config)
print("\t{\t/* between lowmem and PCI hole */", file=config)
print("\t\t.baseaddr = {}UL,\t/* {}MB */".format(
low_mem_to_pci_hole, int(low_mem_to_pci_hole, 16) / 1024 / 1024), file=config)
print("\t\t.length = {}UL,\t/* {}MB */".format(
low_mem_to_pci_hole_len, int(low_mem_to_pci_hole_len, 16) / 1024 / 1024), file=config)
print("\t\t.type = E820_TYPE_RESERVED", file=config)
print("\t},", file=config)
print("", file=config)
print("\t{{\t/* between PCI hole and {}GB */".format(
TOTAL_MEM_SIZE / 1024 / 1024 / 1024), file=config)
print("\t\t.baseaddr = {}UL,\t/* {}GB */".format(
hex(int(pci_hole_addr, 16)), int(pci_hole_addr, 16) / 1024 / 1024 / 1024), file=config)
print("\t\t.length = {}UL,\t/* {}MB */".format(
hex(int(pci_hole_len, 16)), int(pci_hole_len, 16) / 1024 / 1024), file=config)
print("\t\t.type = E820_TYPE_RESERVED", file=config)
print("\t},", file=config)
print("};", file=config)
print("", file=config)
print("/**", file=config)
print(" * @pre vm != NULL", file=config)
print("*/", file=config)
print("void create_prelaunched_vm_e820(struct acrn_vm *vm)", file=config)
print("{", file=config)
print("\tvm->e820_entry_num = VE820_ENTRIES_{};".format(board_name.upper()), file=config)
print("\tvm->e820_entries = ve820_entry;", file=config)
print("}", file=config)
return err_dic
def non_ve820_pre_launch(config):
"""
This is none pre launch vm setting
:param config:
:return:
"""
print("#include <e820.h>", file=config)
print("#include <vm.h>", file=config)
print("/**", file=config)
print(" * @pre vm != NULL", file=config)
print("*/", file=config)
print("void create_prelaunched_vm_e820(struct acrn_vm *vm)", file=config)
print("{", file=config)
print("\tvm->e820_entry_num = 0;", file=config)
print("\tvm->e820_entries = NULL;", file=config)
print("}", file=config)
def generate_file(config):
"""Start to generate board.c
:param config: it is a file pointer of board information for writing to
"""
err_dic = {}
print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
pre_vm_cnt = board_cfg_lib.get_pre_launch_cnt(board_cfg_lib.SCENARIO_INFO_FILE)
# read mem size from scenario.xml
hpa_size_list = board_cfg_lib.get_sub_leaf_tag(
board_cfg_lib.SCENARIO_INFO_FILE, "memory", "size")
ret = board_cfg_lib.is_hpa_size(hpa_size_list)
if not ret:
board_cfg_lib.print_red("Unknow type of host physical address size", err=True)
err_dic['board config: generate ve820.c failed'] = "Unknow type of host physical address size"
return err_dic
hpa_size = hpa_size_list[0]
if pre_vm_cnt != 0 and ('0x' in hpa_size or '0X' in hpa_size):
err_dic = ve820_per_launch(config, hpa_size)
else:
non_ve820_pre_launch(config)
return err_dic