acrn-config: remove the same parameters and functions from board_cfg_lib

Board config should relay on library/common.py and board_cfg_lib, then
remove the duplicate parameters and functions.

Tracked-On: #3854
Signed-off-by: Wei Liu <weix.w.liu@intel.com>
Acked-by: Victor Sun <victor.sun@intel.com>
Acked-by: Terry Zou <terry.zou@intel.com>
This commit is contained in:
Wei Liu
2020-03-26 17:07:49 +08:00
committed by wenlingz
parent 78ce220eb9
commit ed8ac484ad
8 changed files with 76 additions and 180 deletions

View File

@@ -4,6 +4,7 @@
#
import board_cfg_lib
import common
PLATFORM_HEADER = r"""/* DO NOT MODIFY THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
*/
@@ -88,7 +89,7 @@ def multi_info_parser(config, default_platform, msg_s, msg_e):
write_direct = ['PM1A_EVT_ACCESS_SIZE', 'PM1A_EVT_ADDRESS', 'PM1A_CNT_ADDRESS']
pm_ac_sz = OverridAccessSize()
multi_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, msg_s, msg_e)
multi_lines = board_cfg_lib.get_info(common.BOARD_INFO_FILE, msg_s, msg_e)
# S3/S5 not supported by BIOS
sx_name = msg_s.split('_')[0].strip('<')
@@ -129,7 +130,7 @@ def write_direct_info_parser(config, msg_s, msg_e):
: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
"""
vector_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, msg_s, msg_e)
vector_lines = board_cfg_lib.get_info(common.BOARD_INFO_FILE, msg_s, msg_e)
for vector in vector_lines:
print("{}".format(vector.strip()), file=config)
@@ -145,7 +146,7 @@ def drhd_info_parser(config):
prev_num = 0
drhd_lines = board_cfg_lib.get_info(
board_cfg_lib.BOARD_INFO_FILE, "<DRHD_INFO>", "</DRHD_INFO>")
common.BOARD_INFO_FILE, "<DRHD_INFO>", "</DRHD_INFO>")
# write DRHD
print("/* DRHD of DMAR */", file=config)

View File

@@ -7,6 +7,7 @@ import sys
import enum
import subprocess
import board_cfg_lib
import common
class RDT(enum.Enum):
L2 = 0
@@ -28,7 +29,7 @@ MSR_IA32_L3_MASK_END = 0x00000D0F
def gen_dmar_structure(config):
"""Generate dmar structure information"""
dmar_info_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, "<DRHD_INFO>", "</DRHD_INFO>")
dmar_info_lines = board_cfg_lib.get_info(common.BOARD_INFO_FILE, "<DRHD_INFO>", "</DRHD_INFO>")
drhd_cnt = 0
drhd_dev_scope_cnt = []
dev_scope_type = []
@@ -119,7 +120,7 @@ def gen_rdt_res(config):
err_dic = {}
rdt_res_str =""
res_present = [0, 0, 0]
(rdt_resources, rdt_res_clos_max, rdt_res_mask_max) = board_cfg_lib.clos_info_parser(board_cfg_lib.BOARD_INFO_FILE)
(rdt_resources, rdt_res_clos_max, rdt_res_mask_max) = board_cfg_lib.clos_info_parser(common.BOARD_INFO_FILE)
if len(rdt_res_clos_max) != 0:
common_clos_max = min(rdt_res_clos_max)
else:
@@ -159,7 +160,7 @@ def gen_rdt_res(config):
print("};\n", file=config)
res_present[RDT.MBA.value] = 1
else:
err_dic['board config: generate board.c failed'] = "The input of {} was corrupted!".format(board_cfg_lib.BOARD_INFO_FILE)
err_dic['board config: generate board.c failed'] = "The input of {} was corrupted!".format(common.BOARD_INFO_FILE)
return err_dic
if res_present[RDT.L2.value] == 0:
@@ -201,9 +202,9 @@ def gen_px_cx(config):
:param config: it is a file pointer of board information for writing to
"""
cpu_brand_lines = board_cfg_lib.get_info(
board_cfg_lib.BOARD_INFO_FILE, "<CPU_BRAND>", "</CPU_BRAND>")
cx_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, "<CX_INFO>", "</CX_INFO>")
px_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, "<PX_INFO>", "</PX_INFO>")
common.BOARD_INFO_FILE, "<CPU_BRAND>", "</CPU_BRAND>")
cx_lines = board_cfg_lib.get_info(common.BOARD_INFO_FILE, "<CX_INFO>", "</CX_INFO>")
px_lines = board_cfg_lib.get_info(common.BOARD_INFO_FILE, "<PX_INFO>", "</PX_INFO>")
gen_single_data(cx_lines, 'c', config)
gen_single_data(px_lines, 'p', config)

View File

@@ -15,8 +15,8 @@ import misc_cfg_h
import new_board_kconfig
import common
ACRN_PATH = board_cfg_lib.SOURCE_ROOT_DIR
ACRN_CONFIG_TARGET = ACRN_PATH + "hypervisor/arch/x86/configs/"
ACRN_PATH = common.SOURCE_ROOT_DIR
ACRN_CONFIG_DEF = ACRN_PATH + "hypervisor/arch/x86/configs/"
ACRN_DEFAULT_ACPI = ACRN_PATH + "hypervisor/include/arch/x86/default_acpi_info.h"
GEN_FILE = ["pci_devices.h", "board.c", "_acpi_info.h", "misc_cfg.h", ".config"]
@@ -27,48 +27,50 @@ def main(args):
This is main function to start generate source code related with board
:param args: it is a command line args for the script
"""
global ACRN_CONFIG_TARGET
err_dic = {}
(err_dic, board_info_file, scenario_info_file, output_folder) = board_cfg_lib.get_param(args)
(err_dic, board_info_file, scenario_info_file, output_folder) = common.get_param(args)
if err_dic:
return err_dic
if output_folder:
ACRN_CONFIG_TARGET = os.path.abspath(output_folder) + '/'
common.ACRN_CONFIG_TARGET = os.path.abspath(output_folder) + '/'
# check env
err_dic = board_cfg_lib.prepare()
err_dic = common.prepare()
if err_dic:
return err_dic
common.BOARD_INFO_FILE = board_info_file
common.SCENARIO_INFO_FILE = scenario_info_file
common.get_vm_num(scenario_info_file)
board_cfg_lib.BOARD_INFO_FILE = board_info_file
board_cfg_lib.SCENARIO_INFO_FILE = scenario_info_file
board_cfg_lib.get_vm_num(scenario_info_file)
# get board name
(err_dic, board) = board_cfg_lib.get_board_name()
(err_dic, board) = common.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()
(err_dic, status) = common.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
board_dir = ACRN_CONFIG_TARGET + board + '/'
board_cfg_lib.mkdir(board_dir)
if common.ACRN_CONFIG_TARGET:
board_dir = common.ACRN_CONFIG_TARGET + board + '/'
else:
board_dir = ACRN_CONFIG_DEF + board + '/'
common.mkdir(board_dir)
config_pci = board_dir + GEN_FILE[0]
config_board = board_dir + GEN_FILE[1]
config_acpi = board_dir + board + GEN_FILE[2]
config_misc_cfg = board_dir + GEN_FILE[3]
config_board_kconfig = ACRN_CONFIG_TARGET + board + GEN_FILE[4]
if common.ACRN_CONFIG_TARGET:
config_board_kconfig = common.ACRN_CONFIG_TARGET + board + GEN_FILE[4]
else:
config_board_kconfig = ACRN_CONFIG_DEF + board + GEN_FILE[4]
# generate board.c
with open(config_board, 'w+') as config:
@@ -108,7 +110,7 @@ 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()
err_dic = common.prepare()
if err_dic:
return err_dic
@@ -123,4 +125,4 @@ if __name__ == '__main__':
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)
common.print_red("{}: {}".format(err_k, err_v), err=True)

View File

@@ -3,6 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause
#
import common
import board_cfg_lib
MISC_CFG_HEADER = """
@@ -49,21 +50,21 @@ def parse_boot_info():
err_dic = {}
vm_types = []
(err_dic, scenario_name) = board_cfg_lib.get_scenario_name()
(err_dic, scenario_name) = common.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")
sos_cmdlines = common.get_sub_leaf_tag(common.SCENARIO_INFO_FILE, "board_private", "bootargs")
sos_rootfs = common.get_sub_leaf_tag(common.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_cmdlines = common.get_sub_leaf_tag(common.SCENARIO_INFO_FILE, "os_config", "bootargs")
sos_rootfs = board_cfg_lib.get_sub_leaf_tag(board_cfg_lib.SCENARIO_INFO_FILE, "os_config", "rootfs")
sos_rootfs = common.get_sub_leaf_tag(common.SCENARIO_INFO_FILE, "os_config", "rootfs")
(err_dic, vuart0_dic, vuart1_dic) = board_cfg_lib.get_board_private_vuart("os_config", "console")
for i in range(board_cfg_lib.VM_COUNT):
for i in range(common.VM_COUNT):
vm_type = board_cfg_lib.get_order_type_by_vmid(i)
vm_types.append(vm_type)
@@ -77,7 +78,7 @@ def find_hi_mmio_window(config):
mmio_max = 0
is_hi_mmio = False
iomem_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, "<IOMEM_INFO>", "</IOMEM_INFO>")
iomem_lines = board_cfg_lib.get_info(common.BOARD_INFO_FILE, "<IOMEM_INFO>", "</IOMEM_INFO>")
for line in iomem_lines:
if "PCI Bus" not in line:
@@ -85,12 +86,12 @@ def find_hi_mmio_window(config):
line_start_addr = int(line.split('-')[0], 16)
line_end_addr = int(line.split('-')[1].split()[0], 16)
if line_start_addr < board_cfg_lib.SIZE_4G and line_end_addr < board_cfg_lib.SIZE_4G:
if line_start_addr < common.SIZE_4G and line_end_addr < common.SIZE_4G:
continue
elif line_start_addr < board_cfg_lib.SIZE_4G and line_end_addr >= board_cfg_lib.SIZE_4G:
elif line_start_addr < common.SIZE_4G and line_end_addr >= common.SIZE_4G:
i_cnt += 1
is_hi_mmio = True
mmio_min = board_cfg_lib.SIZE_4G
mmio_min = common.SIZE_4G
mmio_max = line_end_addr
continue
@@ -116,7 +117,7 @@ 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)
board_cfg_lib.get_valid_irq(common.BOARD_INFO_FILE)
# get cpu processor list
cpu_list = board_cfg_lib.get_processor_info()
@@ -143,14 +144,14 @@ def generate_file(config):
# 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)
vuart0_setting = board_cfg_lib.get_vuart_info_id(common.SCENARIO_INFO_FILE, 0)
vuart1_setting = board_cfg_lib.get_vuart_info_id(common.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)
(root_devs, root_dev_num) = board_cfg_lib.get_rootfs(common.BOARD_INFO_FILE)
# start to generate misc_cfg.h
print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
@@ -160,7 +161,7 @@ def generate_file(config):
print("#define MAX_PCPU_NUM\t{}U".format(max_cpu_num), file=config)
# set macro of max clos number
(_, clos_max, _) = board_cfg_lib.clos_info_parser(board_cfg_lib.BOARD_INFO_FILE)
(_, clos_max, _) = board_cfg_lib.clos_info_parser(common.BOARD_INFO_FILE)
if len(clos_max) != 0:
common_clos_max = min(clos_max)
else:

View File

@@ -6,6 +6,7 @@
import sys
import subprocess
import board_cfg_lib
import common
DESC = """# Board defconfig generated by acrn-config tool
@@ -26,7 +27,7 @@ VM_NUM_MAP_TOTAL_HV_RAM_SIZE = {
7:0x10E00000,
}
MEM_ALIGN = 2 * board_cfg_lib.SIZE_M
MEM_ALIGN = 2 * common.SIZE_M
def find_avl_memory(ram_range, hpa_size, hv_start_offset):
@@ -62,7 +63,7 @@ def get_ram_range():
ram_range = {}
io_mem_lines = board_cfg_lib.get_info(
board_cfg_lib.BOARD_INFO_FILE, "<IOMEM_INFO>", "</IOMEM_INFO>")
common.BOARD_INFO_FILE, "<IOMEM_INFO>", "</IOMEM_INFO>")
for line in io_mem_lines:
if 'System RAM' not in line:
@@ -81,9 +82,9 @@ def get_serial_type():
ttys_value = ''
# Get ttySx information from board config file
ttys_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, "<TTYS_INFO>", "</TTYS_INFO>")
ttys_lines = board_cfg_lib.get_info(common.BOARD_INFO_FILE, "<TTYS_INFO>", "</TTYS_INFO>")
(err_dic, scenario_name) = board_cfg_lib.get_scenario_name()
(err_dic, scenario_name) = common.get_scenario_name()
if scenario_name == "logical_partition":
ttyn = 'ttyS0'
else:
@@ -112,7 +113,7 @@ def is_rdt_supported():
"""
Returns True if platform supports RDT else False
"""
(rdt_resources, rdt_res_clos_max, _) = board_cfg_lib.clos_info_parser(board_cfg_lib.BOARD_INFO_FILE)
(rdt_resources, rdt_res_clos_max, _) = board_cfg_lib.clos_info_parser(common.BOARD_INFO_FILE)
if len(rdt_resources) == 0 or len(rdt_res_clos_max) == 0:
return False
else:
@@ -127,10 +128,10 @@ def generate_file(config):
# 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]
if common.VM_COUNT in list(VM_NUM_MAP_TOTAL_HV_RAM_SIZE.keys()):
hv_ram_size = VM_NUM_MAP_TOTAL_HV_RAM_SIZE[common.VM_COUNT]
else:
board_cfg_lib.print_red("VM num should not be greater than 8", err=True)
common.print_red("VM num should not be greater than 8", err=True)
err_dic["board config: total vm number error"] = "VM num should not be greater than 8"
return err_dic
@@ -144,10 +145,10 @@ def generate_file(config):
total_size = reserved_ram + hv_ram_size
avl_start_addr = find_avl_memory(ram_range, str(total_size), hv_start_offset)
hv_start_addr = int(avl_start_addr, 16) + int(hex(reserved_ram), 16)
hv_start_addr = board_cfg_lib.round_up(hv_start_addr, MEM_ALIGN)
hv_start_addr = common.round_up(hv_start_addr, MEM_ALIGN)
# add config scenario name
(err_dic, scenario_name) = board_cfg_lib.get_scenario_name()
(err_dic, scenario_name) = common.get_scenario_name()
print("{}".format(DESC), file=config)
print("CONFIG_{}=y".format(scenario_name.upper()), file=config)

View File

@@ -5,6 +5,7 @@
import collections
import board_cfg_lib
import common
PCI_HEADER = r"""
#ifndef PCI_DEVICES_H_
@@ -59,11 +60,11 @@ def get_size(line):
# get size string from format, Region n: Memory at x ... [size=NK]
size_str = line.split()[-1].strip(']').split('=')[1]
if 'G' in size_str:
size = int(size_str.strip('G')) * board_cfg_lib.SIZE_G
size = int(size_str.strip('G')) * common.SIZE_G
elif 'M' in size_str:
size = int(size_str.strip('M')) * board_cfg_lib.SIZE_M
size = int(size_str.strip('M')) * common.SIZE_M
elif 'K' in size_str:
size = int(size_str.strip('K')) * board_cfg_lib.SIZE_K
size = int(size_str.strip('K')) * common.SIZE_K
else:
size = int(size_str)
@@ -74,7 +75,7 @@ def remap_bar_addr_to_high(bar_addr, line):
"""Generate vbar address"""
global HI_MMIO_OFFSET
size = get_size(line)
cur_addr = board_cfg_lib.round_up(bar_addr, size)
cur_addr = common.round_up(bar_addr, size)
HI_MMIO_OFFSET = cur_addr + size
return cur_addr
@@ -88,7 +89,7 @@ def parser_pci():
cal_sub_pci_name = []
pci_lines = board_cfg_lib.get_info(
board_cfg_lib.BOARD_INFO_FILE, "<PCI_DEVICE>", "</PCI_DEVICE>")
common.BOARD_INFO_FILE, "<PCI_DEVICE>", "</PCI_DEVICE>")
for line in pci_lines:
tmp_bar_mem = Bar_Mem()
@@ -100,7 +101,7 @@ def parser_pci():
bar_addr = int(get_value_after_str(line, "at"), 16)
bar_num = line.split()[1].strip(':')
if bar_addr >= board_cfg_lib.SIZE_4G or bar_addr < board_cfg_lib.SIZE_2G:
if bar_addr >= common.SIZE_4G or bar_addr < common.SIZE_2G:
if not tmp_bar_attr.remappable:
continue
@@ -155,7 +156,7 @@ def write_pbdf(i_cnt, bdf, bar_attr, config):
tmp_sub_name = "_".join(bar_attr.name.split()).upper()
else:
if '-' in bar_attr.name:
tmp_sub_name = board_cfg_lib.undline_name(bar_attr.name) + "_" + str(i_cnt)
tmp_sub_name = common.undline_name(bar_attr.name) + "_" + str(i_cnt)
else:
tmp_sub_name = "_".join(bar_attr.name.split()).upper() + "_" + str(i_cnt)
@@ -185,7 +186,7 @@ def write_vbar(i_cnt, bdf, pci_bar_dic, bar_attr, config):
align = ' ' * 48
ptdev_mmio_str = ''
tmp_sub_name = board_cfg_lib.undline_name(bar_attr.name) + "_" + str(i_cnt)
tmp_sub_name = common.undline_name(bar_attr.name) + "_" + str(i_cnt)
if bdf in pci_bar_dic.keys():
bar_list = list(pci_bar_dic[bdf].keys())
bar_len = len(bar_list)