acrn-config: support '--out' option for board/scenario/launch config

Currently, config tool generate board files and scenario files in
acrn-hypervisor directory, the origin souce code would be corrupted by
the config tool. Config tool add '--out' option for user to give a path
to store the generated files, without this option, tool will generate
files in origin source code.

Tracked-On: #4517
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 2020-03-17 11:16:54 +08:00 committed by wenlingz
parent 6b9c1f2d31
commit e1ae5ba638
7 changed files with 95 additions and 67 deletions

View File

@ -15,34 +15,27 @@ import misc_cfg_h
import new_board_kconfig import new_board_kconfig
ACRN_PATH = board_cfg_lib.SOURCE_ROOT_DIR ACRN_PATH = board_cfg_lib.SOURCE_ROOT_DIR
ACRN_CONFIG = ACRN_PATH + "hypervisor/arch/x86/configs/" ACRN_CONFIG_TARGET = ACRN_PATH + "hypervisor/arch/x86/configs/"
ACRN_DEFAULT_PLATFORM = ACRN_PATH + "hypervisor/include/arch/x86/default_acpi_info.h" 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"] GEN_FILE = ["pci_devices.h", "board.c", "_acpi_info.h", "misc_cfg.h", ".config"]
def need_gen_new_board_config(board_name):
# 1. if it is old board, they are already have the $(board_name).config, return and no need to generate it.
if board_name in board_cfg_lib.BOARD_NAMES:
return False
else:
return True
def main(args): def main(args):
""" """
This is main function to start generate source code related with board This is main function to start generate source code related with board
:param args: it is a command line args for the script :param args: it is a command line args for the script
""" """
global ACRN_CONFIG_TARGET
err_dic = {} err_dic = {}
config_dirs = []
(err_dic, board_info_file, scenario_info_file) = board_cfg_lib.get_param(args) (err_dic, board_info_file, scenario_info_file, output_folder) = board_cfg_lib.get_param(args)
if err_dic: if err_dic:
return err_dic return err_dic
if output_folder:
ACRN_CONFIG_TARGET = os.path.abspath(output_folder) + '/'
# check env # check env
err_dic = board_cfg_lib.prepare() err_dic = board_cfg_lib.prepare()
if err_dic: if err_dic:
@ -64,17 +57,14 @@ def main(args):
err_dic['board config: Not match'] = "The board xml and scenario xml should be matched" err_dic['board config: Not match'] = "The board xml and scenario xml should be matched"
return err_dic return err_dic
config_dirs.append(ACRN_CONFIG + board) board_dir = ACRN_CONFIG_TARGET + board + '/'
if board not in board_cfg_lib.BOARD_NAMES: board_cfg_lib.mkdir(board_dir)
for config_dir in config_dirs:
if not os.path.exists(config_dir):
os.makedirs(config_dir)
config_pci = config_dirs[0] + '/' + GEN_FILE[0] config_pci = board_dir + GEN_FILE[0]
config_board = config_dirs[0] + '/' + GEN_FILE[1] config_board = board_dir + GEN_FILE[1]
config_platform = config_dirs[0] + '/' + board + GEN_FILE[2] config_acpi = board_dir + board + GEN_FILE[2]
config_misc_cfg = config_dirs[0] + '/' + GEN_FILE[3] config_misc_cfg = board_dir + GEN_FILE[3]
config_board_kconfig = ACRN_CONFIG + board + GEN_FILE[4] config_board_kconfig = ACRN_CONFIG_TARGET + board + GEN_FILE[4]
# generate board.c # generate board.c
with open(config_board, 'w+') as config: with open(config_board, 'w+') as config:
@ -86,9 +76,9 @@ def main(args):
with open(config_pci, 'w+') as config: with open(config_pci, 'w+') as config:
pci_devices_h.generate_file(config) pci_devices_h.generate_file(config)
# generate acpi_platform.h # generate ($board)_acpi_info.h
with open(config_platform, 'w+') as config: with open(config_acpi, 'w+') as config:
acpi_platform_h.generate_file(config, ACRN_DEFAULT_PLATFORM) acpi_platform_h.generate_file(config, ACRN_DEFAULT_ACPI)
# generate misc_cfg.h # generate misc_cfg.h
with open(config_misc_cfg, 'w+') as config: with open(config_misc_cfg, 'w+') as config:
@ -96,19 +86,16 @@ def main(args):
if err_dic: if err_dic:
return err_dic return err_dic
# generate new board_name.config # generate ($board).config
if need_gen_new_board_config(board): with open(config_board_kconfig, 'w+') as config:
with open(config_board_kconfig, 'w+') as config: err_dic = new_board_kconfig.generate_file(config)
err_dic = new_board_kconfig.generate_file(config) if err_dic:
if err_dic: return err_dic
return err_dic
if board not in board_cfg_lib.BOARD_NAMES and not err_dic: if not err_dic:
print("Config files for NEW board {} is generated successfully!".format(board )) print("Board configurations for {} is generated successfully.".format(board))
elif not err_dic:
print("Config files for {} is generated successfully!".format(board))
else: else:
print("Config files for {} is failed".format(board)) print("Board configurations for {} is generated failed.".format(board))
return err_dic return err_dic

View File

@ -11,7 +11,7 @@ import launch_cfg_lib
import com import com
ACRN_PATH = launch_cfg_lib.SOURCE_ROOT_DIR ACRN_PATH = launch_cfg_lib.SOURCE_ROOT_DIR
XML_PATH = ACRN_PATH + '/misc/acrn-config/xmls/config-xmls/' ACRN_CONFIG_TARGET = ACRN_PATH + '/misc/acrn-config/xmls/config-xmls/'
def get_launch_item_values(board_info): def get_launch_item_values(board_info):
@ -142,12 +142,15 @@ def main(args):
This is main function to start generate launch script This is main function to start generate launch script
:param args: it is a command line args for the script :param args: it is a command line args for the script
""" """
global ACRN_CONFIG_TARGET
# get parameters # get parameters
(err_dic, board_info_file, scenario_info_file, launch_info_file, vm_th) = launch_cfg_lib.get_param(args) (err_dic, board_info_file, scenario_info_file, launch_info_file, vm_th, output_folder) = launch_cfg_lib.get_param(args)
if err_dic: if err_dic:
return err_dic return err_dic
if output_folder:
ACRN_CONFIG_TARGET = os.path.abspath(output_folder) + '/'
# check env # check env
err_dic = launch_cfg_lib.prepare() err_dic = launch_cfg_lib.prepare()
if err_dic: if err_dic:
@ -197,9 +200,8 @@ def main(args):
# create output directory # create output directory
board_name = names['board_name'] board_name = names['board_name']
output = XML_PATH + '/' + board_name + '/output/' output = ACRN_CONFIG_TARGET + '/' + board_name + '/output/'
if not os.path.exists(output): launch_cfg_lib.mkdir(output)
os.makedirs(output)
# generate launch script # generate launch script
if vm_th: if vm_th:

View File

@ -433,3 +433,8 @@ def undline_name(name):
def round_up(addr, mem_align): def round_up(addr, mem_align):
"""Keep memory align""" """Keep memory align"""
return common.round_up(addr, mem_align) return common.round_up(addr, mem_align)
def mkdir(path):
common.mkdir(path)

View File

@ -81,9 +81,10 @@ def print_if_red(msg, err=False):
def usage(file_name): def usage(file_name):
""" This is usage for how to use this tool """ """ This is usage for how to use this tool """
print("usage= {} [h] ".format(file_name), end="") print("usage= {} [h] ".format(file_name), end="")
print("--board <board_info_file> --scenario <scenario_info_file>") print("--board <board_info_file> --scenario <scenario_info_file> --out [output folder]")
print('board_info_file : file name of the board info') print('board_info_file : file name of the board info')
print('scenario_info_file : file name of the scenario info') print('scenario_info_file : file name of the scenario info')
print('output folder : path to acrn-hypervisor_folder')
def get_param(args): def get_param(args):
@ -94,34 +95,37 @@ def get_param(args):
err_dic = {} err_dic = {}
board_info_file = False board_info_file = False
scenario_info_file = False scenario_info_file = False
output_folder = False
if '--board' not in args or '--scenario' not in args: if '--board' not in args or '--scenario' not in args:
usage(args[0]) usage(args[0])
err_dic['common error: get wrong parameter'] = "wrong usage" err_dic['common error: get wrong parameter'] = "wrong usage"
return (err_dic, board_info_file, scenario_info_file) return (err_dic, board_info_file, scenario_info_file, output_folder)
args_list = args[1:] args_list = args[1:]
(optlist, args_list) = getopt.getopt(args_list, '', ['board=', 'scenario=']) (optlist, args_list) = getopt.getopt(args_list, '', ['board=', 'scenario=', 'out='])
for arg_k, arg_v in optlist: for arg_k, arg_v in optlist:
if arg_k == '--board': if arg_k == '--board':
board_info_file = arg_v board_info_file = arg_v
if arg_k == '--scenario': if arg_k == '--scenario':
scenario_info_file = arg_v scenario_info_file = arg_v
if arg_k == '--out':
output_folder = arg_v
if not board_info_file or not scenario_info_file: if not board_info_file or not scenario_info_file:
usage(args[0]) usage(args[0])
err_dic['common error: get wrong parameter'] = "wrong usage" err_dic['common error: get wrong parameter'] = "wrong usage"
return (err_dic, board_info_file, scenario_info_file) return (err_dic, board_info_file, scenario_info_file, output_folder)
if not os.path.exists(board_info_file): if not os.path.exists(board_info_file):
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(board_info_file) err_dic['common error: get wrong parameter'] = "{} is not exist!".format(board_info_file)
return (err_dic, board_info_file, scenario_info_file) return (err_dic, board_info_file, scenario_info_file, output_folder)
if not os.path.exists(scenario_info_file): if not os.path.exists(scenario_info_file):
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(scenario_info_file) err_dic['common error: get wrong parameter'] = "{} is not exist!".format(scenario_info_file)
return (err_dic, board_info_file, scenario_info_file) return (err_dic, board_info_file, scenario_info_file, output_folder)
return (err_dic, board_info_file, scenario_info_file) return (err_dic, board_info_file, scenario_info_file, output_folder)
def check_env(): def check_env():
@ -643,3 +647,12 @@ def get_vuart_info_id(config_file, idx):
def round_up(addr, mem_align): def round_up(addr, mem_align):
"""Keep memory align""" """Keep memory align"""
return ((addr + (mem_align - 1)) & (~(mem_align - 1))) return ((addr + (mem_align - 1)) & (~(mem_align - 1)))
def mkdir(path):
if not os.path.exists(path):
try:
subprocess.check_call('mkdir -p {}'.format(path), shell=True, stdout=subprocess.PIPE)
except subprocess.CalledProcessError:
print_if_red("{} file create failed!".format(path), err=True)

View File

@ -86,11 +86,12 @@ def print_red(msg, err=False):
def usage(file_name): def usage(file_name):
""" This is usage for how to use this tool """ """ This is usage for how to use this tool """
print("usage= {} [h]".format(file_name), end="") print("usage= {} [h]".format(file_name), end="")
print("--board <board_info_file> --scenario <scenario_info_file> --launch <launch_info_file> --uosid <uosid id>") print("--board <board_info_file> --scenario <scenario_info_file> --launch <launch_info_file> --uosid <uosid id> --out [output folder]")
print('board_info_file : file name of the board info') print('board_info_file : file name of the board info')
print('scenario_info_file : file name of the scenario info') print('scenario_info_file : file name of the scenario info')
print('launch_info_file : file name of the launch info') print('launch_info_file : file name of the launch info')
print('uosid : this is the relateive id for post launch vm in scenario info XML:[1..max post launch vm]') print('uosid : this is the relateive id for post launch vm in scenario info XML:[1..max post launch vm]')
print('output folder : path to acrn-hypervisor_folder')
def get_param(args): def get_param(args):
@ -103,6 +104,7 @@ def get_param(args):
board_info_file = False board_info_file = False
scenario_info_file = False scenario_info_file = False
launch_info_file = False launch_info_file = False
output_folder = False
param_list = ['--board', '--scenario', '--launch', '--uosid'] param_list = ['--board', '--scenario', '--launch', '--uosid']
for arg_str in param_list: for arg_str in param_list:
@ -110,10 +112,10 @@ def get_param(args):
if arg_str not in args: if arg_str not in args:
usage(args[0]) usage(args[0])
err_dic['common error: get wrong parameter'] = "wrong usage" err_dic['common error: get wrong parameter'] = "wrong usage"
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th)) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder)
args_list = args[1:] args_list = args[1:]
(optlist, args_list) = getopt.getopt(args_list, '', ['board=', 'scenario=', 'launch=', 'uosid=']) (optlist, args_list) = getopt.getopt(args_list, '', ['board=', 'scenario=', 'launch=', 'uosid=', 'out='])
for arg_k, arg_v in optlist: for arg_k, arg_v in optlist:
if arg_k == '--board': if arg_k == '--board':
board_info_file = arg_v board_info_file = arg_v
@ -121,31 +123,33 @@ def get_param(args):
scenario_info_file = arg_v scenario_info_file = arg_v
if arg_k == '--launch': if arg_k == '--launch':
launch_info_file = arg_v launch_info_file = arg_v
if arg_k == '--out':
output_folder = arg_v
if '--uosid' in args: if '--uosid' in args:
if arg_k == '--uosid': if arg_k == '--uosid':
vm_th = arg_v vm_th = arg_v
if not vm_th.isnumeric(): if not vm_th.isnumeric():
err_dic['common error: get wrong parameter'] = "--uosid should be a number" err_dic['common error: get wrong parameter'] = "--uosid should be a number"
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th)) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder)
if not board_info_file or not scenario_info_file or not launch_info_file: if not board_info_file or not scenario_info_file or not launch_info_file:
usage(args[0]) usage(args[0])
err_dic['common error: get wrong parameter'] = "wrong usage" err_dic['common error: get wrong parameter'] = "wrong usage"
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th)) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder)
if not os.path.exists(board_info_file): if not os.path.exists(board_info_file):
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(board_info_file) err_dic['common error: get wrong parameter'] = "{} is not exist!".format(board_info_file)
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th)) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder)
if not os.path.exists(scenario_info_file): if not os.path.exists(scenario_info_file):
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(scenario_info_file) err_dic['common error: get wrong parameter'] = "{} is not exist!".format(scenario_info_file)
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th)) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder)
if not os.path.exists(launch_info_file): if not os.path.exists(launch_info_file):
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(launch_info_file) err_dic['common error: get wrong parameter'] = "{} is not exist!".format(launch_info_file)
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th)) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder)
return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th)) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder)
def get_post_num_list(): def get_post_num_list():
@ -692,3 +696,8 @@ def bdf_duplicate_check(bdf_dic):
return return
else: else:
bdf_used.append(dev_bdf) bdf_used.append(dev_bdf)
def mkdir(path):
common.mkdir(path)

View File

@ -708,3 +708,8 @@ def get_first_post_vm():
break break
return (err_dic, i) return (err_dic, i)
def mkdir(path):
common.mkdir(path)

View File

@ -14,7 +14,7 @@ import vm_configurations_h
import pci_dev_c import pci_dev_c
ACRN_PATH = scenario_cfg_lib.SOURCE_ROOT_DIR ACRN_PATH = scenario_cfg_lib.SOURCE_ROOT_DIR
SCENARIO_PATH = ACRN_PATH + 'hypervisor/scenarios' ACRN_CONFIG_TARGET = ACRN_PATH + 'hypervisor/scenarios/'
GEN_FILE = ["vm_configurations.h", "vm_configurations.c", "pci_dev.c"] GEN_FILE = ["vm_configurations.h", "vm_configurations.c", "pci_dev.c"]
@ -76,12 +76,16 @@ def main(args):
This is main function to start generate source code related with board This is main function to start generate source code related with board
:param args: it is a command line args for the script :param args: it is a command line args for the script
""" """
global ACRN_CONFIG_TARGET
err_dic = {} err_dic = {}
(err_dic, board_info_file, scenario_info_file) = scenario_cfg_lib.get_param(args) (err_dic, board_info_file, scenario_info_file, output_folder) = scenario_cfg_lib.get_param(args)
if err_dic: if err_dic:
return err_dic return err_dic
if output_folder:
ACRN_CONFIG_TARGET = os.path.abspath(output_folder) + '/'
# check env # check env
err_dic = scenario_cfg_lib.prepare() err_dic = scenario_cfg_lib.prepare()
if err_dic: if err_dic:
@ -101,9 +105,12 @@ def main(args):
err_dic['scenario config: Not match'] = "The board xml and scenario xml should be matched!" err_dic['scenario config: Not match'] = "The board xml and scenario xml should be matched!"
return err_dic return err_dic
vm_config_h = SCENARIO_PATH + '/' + scenario + '/' + GEN_FILE[0] scenario_dir = ACRN_CONFIG_TARGET + scenario + '/'
vm_config_c = SCENARIO_PATH + '/' + scenario + '/' + GEN_FILE[1] scenario_cfg_lib.mkdir(scenario_dir)
pci_config_c = SCENARIO_PATH + '/' + scenario + '/' + GEN_FILE[2]
vm_config_h = scenario_dir + GEN_FILE[0]
vm_config_c = scenario_dir + GEN_FILE[1]
pci_config_c = scenario_dir + GEN_FILE[2]
# parse the scenario.xml # parse the scenario.xml
get_scenario_item_values(board_info_file, scenario_info_file) get_scenario_item_values(board_info_file, scenario_info_file)
@ -135,9 +142,9 @@ def main(args):
pci_dev_c.generate_file(config) pci_dev_c.generate_file(config)
if not err_dic: if not err_dic:
print("Config files for {} is generated successfully!".format(scenario)) print("Scenario configurations for {} is generated successfully.".format(scenario))
else: else:
print("Config files for {} is failed".format(scenario)) print("Scenario configurations for {} is generated failed.".format(scenario))
return err_dic return err_dic