2019-07-30 09:20:40 +08:00
|
|
|
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2019-09-05 13:31:11 +08:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'library'))
|
2019-07-30 09:20:40 +08:00
|
|
|
import board_cfg_lib
|
|
|
|
import board_c
|
|
|
|
import pci_devices_h
|
|
|
|
import acpi_platform_h
|
2019-09-05 13:31:11 +08:00
|
|
|
import misc_cfg_h
|
2020-03-19 21:42:01 +08:00
|
|
|
import common
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-03-26 17:07:49 +08:00
|
|
|
ACRN_PATH = common.SOURCE_ROOT_DIR
|
|
|
|
ACRN_CONFIG_DEF = ACRN_PATH + "hypervisor/arch/x86/configs/"
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-03-17 11:16:54 +08:00
|
|
|
ACRN_DEFAULT_ACPI = ACRN_PATH + "hypervisor/include/arch/x86/default_acpi_info.h"
|
2020-03-06 08:23:48 +08:00
|
|
|
GEN_FILE = ["pci_devices.h", "board.c", "_acpi_info.h", "misc_cfg.h", ".config"]
|
2019-07-30 09:20:40 +08:00
|
|
|
|
|
|
|
|
2019-09-05 13:31:11 +08:00
|
|
|
def main(args):
|
2019-08-02 19:17:58 +08:00
|
|
|
"""
|
2019-09-05 13:31:11 +08:00
|
|
|
This is main function to start generate source code related with board
|
|
|
|
:param args: it is a command line args for the script
|
2019-08-02 19:17:58 +08:00
|
|
|
"""
|
2019-09-05 13:31:11 +08:00
|
|
|
err_dic = {}
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-04-04 10:26:01 +08:00
|
|
|
(err_dic, params) = common.get_param(args)
|
2019-09-05 13:31:11 +08:00
|
|
|
if err_dic:
|
|
|
|
return err_dic
|
|
|
|
|
2019-10-22 19:21:10 +08:00
|
|
|
# check env
|
2020-03-26 17:07:49 +08:00
|
|
|
err_dic = common.prepare()
|
2019-10-22 19:21:10 +08:00
|
|
|
if err_dic:
|
|
|
|
return err_dic
|
|
|
|
|
2020-04-04 10:26:01 +08:00
|
|
|
common.BOARD_INFO_FILE = params['--board']
|
|
|
|
common.SCENARIO_INFO_FILE = params['--scenario']
|
|
|
|
common.get_vm_num(params['--scenario'])
|
2020-04-07 09:00:24 +08:00
|
|
|
common.get_vm_types()
|
2019-09-05 13:31:11 +08:00
|
|
|
|
2020-04-21 18:12:05 +08:00
|
|
|
if common.VM_COUNT > common.MAX_VM_NUM:
|
|
|
|
err_dic['vm count'] = "The vm count in config xml should be less or equal {}!".format(common.MAX_VM_NUM)
|
|
|
|
return err_dic
|
|
|
|
|
|
|
|
# check if this is the scenario config which matched board info
|
2019-07-30 09:20:40 +08:00
|
|
|
# get board name
|
2020-03-26 17:07:49 +08:00
|
|
|
(err_dic, board) = common.get_board_name()
|
2019-09-05 13:31:11 +08:00
|
|
|
if err_dic:
|
|
|
|
return err_dic
|
|
|
|
board_cfg_lib.BOARD_NAME = board
|
|
|
|
|
|
|
|
# check if this is the scenario config which matched board info
|
2020-03-26 17:07:49 +08:00
|
|
|
(err_dic, status) = common.is_config_file_match()
|
2019-09-05 13:31:11 +08:00
|
|
|
if not status:
|
|
|
|
err_dic['board config: Not match'] = "The board xml and scenario xml should be matched"
|
|
|
|
return err_dic
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-04-16 16:50:11 +08:00
|
|
|
if params['--out']:
|
|
|
|
if os.path.isabs(params['--out']):
|
2020-04-21 14:13:48 +08:00
|
|
|
board_dir = os.path.join(params['--out'], board + '/')
|
|
|
|
config_board_kconfig = os.path.join(board_dir, GEN_FILE[4])
|
2020-04-16 16:50:11 +08:00
|
|
|
else:
|
2020-04-21 14:13:48 +08:00
|
|
|
board_dir = os.path.join(ACRN_PATH + params['--out'], board + '/')
|
|
|
|
config_board_kconfig = os.path.join(board_dir, GEN_FILE[4])
|
2020-03-26 17:07:49 +08:00
|
|
|
else:
|
2020-04-21 14:13:48 +08:00
|
|
|
board_dir = os.path.join(ACRN_CONFIG_DEF, board + '/')
|
|
|
|
config_board_kconfig = os.path.join(board_dir, GEN_FILE[4])
|
2020-03-26 17:07:49 +08:00
|
|
|
common.mkdir(board_dir)
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-03-17 11:16:54 +08:00
|
|
|
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]
|
2019-07-30 09:20:40 +08:00
|
|
|
|
|
|
|
# generate board.c
|
|
|
|
with open(config_board, 'w+') as config:
|
2019-09-05 13:31:11 +08:00
|
|
|
err_dic = board_c.generate_file(config)
|
|
|
|
if err_dic:
|
|
|
|
return err_dic
|
2019-07-30 09:20:40 +08:00
|
|
|
|
|
|
|
# generate pci_devices.h
|
|
|
|
with open(config_pci, 'w+') as config:
|
|
|
|
pci_devices_h.generate_file(config)
|
|
|
|
|
2020-03-17 11:16:54 +08:00
|
|
|
# generate ($board)_acpi_info.h
|
|
|
|
with open(config_acpi, 'w+') as config:
|
|
|
|
acpi_platform_h.generate_file(config, ACRN_DEFAULT_ACPI)
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-03-06 08:23:48 +08:00
|
|
|
# generate misc_cfg.h
|
2019-09-05 13:31:11 +08:00
|
|
|
with open(config_misc_cfg, 'w+') as config:
|
|
|
|
err_dic = misc_cfg_h.generate_file(config)
|
|
|
|
if err_dic:
|
|
|
|
return err_dic
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-03-17 11:16:54 +08:00
|
|
|
if not err_dic:
|
|
|
|
print("Board configurations for {} is generated successfully.".format(board))
|
2019-09-05 13:31:11 +08:00
|
|
|
else:
|
2020-03-17 11:16:54 +08:00
|
|
|
print("Board configurations for {} is generated failed.".format(board))
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2019-09-05 13:31:11 +08:00
|
|
|
return err_dic
|
2019-07-30 09:20:40 +08:00
|
|
|
|
|
|
|
|
2020-04-21 18:12:05 +08:00
|
|
|
def ui_entry_api(board_info, scenario_info, out=''):
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-04-16 16:50:11 +08:00
|
|
|
arg_list = ['board_cfg_gen.py', '--board', board_info, '--scenario', scenario_info, '--out', out]
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-03-26 17:07:49 +08:00
|
|
|
err_dic = common.prepare()
|
2019-09-05 13:31:11 +08:00
|
|
|
if err_dic:
|
|
|
|
return err_dic
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2019-09-05 13:31:11 +08:00
|
|
|
err_dic = main(arg_list)
|
|
|
|
|
|
|
|
return err_dic
|
2019-07-30 09:20:40 +08:00
|
|
|
|
|
|
|
|
2019-09-05 13:31:11 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
ARGS = sys.argv
|
|
|
|
err_dic = main(ARGS)
|
|
|
|
if err_dic:
|
|
|
|
for err_k, err_v in err_dic.items():
|
2020-03-26 17:07:49 +08:00
|
|
|
common.print_red("{}: {}".format(err_k, err_v), err=True)
|