Skip to content

Commit 8a16d8b

Browse files
Wei Liuwenlingz
authored andcommitted
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>
1 parent 77c17ab commit 8a16d8b

21 files changed

+3908
-275
lines changed

misc/acrn-config/board_config/acpi_platform_h.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@
1414

1515
PLATFORM_END_HEADER = "\n#endif /* PLATFORM_ACPI_INFO_H */"
1616

17+
1718
class OverridAccessSize():
18-
"""The Pm access size which are needed to redefine"""
19+
""" The Pm access size which are needed to redefine """
1920
def __init__(self):
2021
self.pm1a_cnt_ac_sz = True
2122
self.pm1b_cnt_ac_sz = True
2223
self.pm1b_evt_ac_sz = True
2324

2425
def style_check_1(self):
25-
"""Style check if have public method"""
26+
""" Style check if have public method """
2627
self.pm1a_cnt_ac_sz = True
2728

2829
def style_check_2(self):
29-
"""Style check if have public method"""
30+
""" Style check if have public method """
3031
self.pm1a_cnt_ac_sz = True
3132

3233

3334
def multi_parser(line, s_line, pm_ac_sz, config):
34-
"""Multi parser the line
35+
"""
36+
Multi parse the line
3537
:param line: it is a line read from default_acpi_info.h
3638
:param s_line: it is a line read from board information file
3739
: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):
7678

7779

7880
def multi_info_parser(config, default_platform, msg_s, msg_e):
79-
"""Parser multi information
81+
"""
82+
Parse multi information
8083
:param config: it is a file pointer to write acpi information
8184
:param default_platform: it is the default_acpi_info.h in acrn-hypervisor
8285
: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):
109112

110113

111114
def write_direct_info_parser(config, msg_s, msg_e):
112-
"""Direct to write
115+
"""
116+
Direct to write
113117
:param config: it is a file pointer to write acpi information
114118
:param msg_s: it is a pattern of key stings what start to match from board information
115119
: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):
123127

124128

125129
def drhd_info_parser(config):
126-
"""Parser DRHD information
130+
"""
131+
Parse DRHD information
127132
:param config: it is a file pointer to write acpi information
128133
"""
129134
prev_num = 0
@@ -149,7 +154,8 @@ def drhd_info_parser(config):
149154

150155

151156
def platform_info_parser(config, default_platform):
152-
"""Parser ACPI information
157+
"""
158+
Parse ACPI information
153159
:param config: it is a file pointer to write acpi information
154160
:param default_platform: it is the default_acpi_info.h in acrn-hypervisor
155161
"""
@@ -165,7 +171,8 @@ def platform_info_parser(config, default_platform):
165171

166172

167173
def generate_file(config, default_platform):
168-
"""write board_name_acpi_info.h
174+
"""
175+
write board_name_acpi_info.h
169176
:param config: it is a file pointer to write acpi information
170177
:param default_platform: it is the default_acpi_info.h in acrn-hypervisor
171178
"""
@@ -174,7 +181,7 @@ def generate_file(config, default_platform):
174181
print("{}".format(PLATFORM_HEADER), file=config)
175182

176183
board_cfg_lib.handle_bios_info(config)
177-
# parser for the platform info
184+
# parse for the platform info
178185
platform_info_parser(config, default_platform)
179186

180187
print("{}".format(PLATFORM_END_HEADER), file=config)

misc/acrn-config/board_config/board_c.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,17 @@
77
import board_cfg_lib
88

99

10-
def clos_info_parser():
11-
"""Parser CLOS information"""
12-
13-
cache_support = False
14-
clos_max = 0
15-
16-
cat_lines = board_cfg_lib.get_info(
17-
board_cfg_lib.BOARD_INFO_FILE, "<CLOS_INFO>", "</CLOS_INFO>")
18-
19-
for line in cat_lines:
20-
if line.split(':')[0] == "clos supported by cache":
21-
cache_support = line.split(':')[1].strip()
22-
elif line.split(':')[0] == "clos max":
23-
clos_max = int(line.split(':')[1])
24-
25-
return (cache_support, clos_max)
26-
27-
2810
def gen_cat(config):
29-
"""Get CAT information
11+
"""
12+
Get CAT information
3013
:param config: it is a file pointer of board information for writing to
3114
"""
32-
(cache_support, clos_max) = clos_info_parser()
15+
err_dic = {}
16+
(cache_support, clos_max) = board_cfg_lib.clos_info_parser(board_cfg_lib.BOARD_INFO_FILE)
3317

3418
print("\n#include <board.h>", file=config)
3519
print("#include <acrn_common.h>", file=config)
20+
print("#include <msr.h>", file=config)
3621

3722
if cache_support == "False" or clos_max == 0:
3823
print("\nstruct platform_clos_info platform_clos_array[0];", file=config)
@@ -50,9 +35,8 @@ def gen_cat(config):
5035
elif cache_support == "L3":
5136
print("\t\t.msr_index = {0}U,".format(hex(0x00000C90+i_cnt)), file=config)
5237
else:
53-
board_cfg_lib.print_red("The input of {} was corrupted!".format(
54-
board_cfg_lib.BOARD_INFO_FILE))
55-
sys.exit(1)
38+
err_dic['board config: generate board.c failed'] = "The input of {} was corrupted!".format(board_cfg_lib.BOARD_INFO_FILE)
39+
return err_dic
5640
print("\t},", file=config)
5741

5842
print("};\n", file=config)
@@ -61,10 +45,12 @@ def gen_cat(config):
6145
file=config)
6246

6347
print("", file=config)
48+
return err_dic
6449

6550

6651
def gen_px_cx(config):
67-
"""Get Px/Cx and store them to board.c
52+
"""
53+
Get Px/Cx and store them to board.c
6854
:param config: it is a file pointer of board information for writing to
6955
"""
7056
cpu_brand_lines = board_cfg_lib.get_info(
@@ -97,16 +83,22 @@ def gen_px_cx(config):
9783

9884

9985
def generate_file(config):
100-
"""Start to generate board.c
86+
"""
87+
Start to generate board.c
10188
:param config: it is a file pointer of board information for writing to
10289
"""
90+
err_dic = {}
10391
print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
10492

10593
# insert bios info into board.c
10694
board_cfg_lib.handle_bios_info(config)
10795

10896
# start to parser to get CAT info
109-
gen_cat(config)
97+
err_dic = gen_cat(config)
98+
if err_dic:
99+
return err_dic
110100

111101
# start to parser PX/CX info
112102
gen_px_cx(config)
103+
104+
return err_dic

misc/acrn-config/board_config/board_cfg_gen.py

Lines changed: 85 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,97 +6,79 @@
66

77
import os
88
import sys
9-
import shutil
10-
import subprocess
9+
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'library'))
1110
import board_cfg_lib
1211
import board_c
1312
import pci_devices_h
1413
import acpi_platform_h
14+
import misc_cfg_h
15+
import ve820_c
16+
import new_board_kconfig
1517

16-
ACRN_PATH = "../../../"
18+
ACRN_PATH = board_cfg_lib.SOURCE_ROOT_DIR
1719
ACRN_CONFIG = ACRN_PATH + "hypervisor/arch/x86/configs/"
1820

1921
BOARD_NAMES = ['apl-mrb', 'apl-nuc', 'apl-up2', 'dnv-cb2', 'nuc6cayh',
2022
'nuc7i7dnb', 'kbl-nuc-i7', 'icl-rvp']
2123

2224
ACRN_DEFAULT_PLATFORM = ACRN_PATH + "hypervisor/include/arch/x86/default_acpi_info.h"
23-
GEN_FILE = ["vm_configurations.h", "vm_configurations.c", "pt_dev.c", "pci_devices.h",
24-
"board.c", "_acpi_info.h"]
25+
GEN_FILE = ["pci_devices.h", "board.c", "_acpi_info.h", "misc_cfg.h", "ve820.c", ".config"]
2526

26-
PY_CACHES = ["__pycache__", "board_config/__pycache__"]
27-
BIN_LIST = ['git']
2827

29-
30-
def prepare():
31-
"""Prepare to check the environment"""
32-
for excute in BIN_LIST:
33-
res = subprocess.Popen("which {}".format(excute), shell=True, stdout=subprocess.PIPE,
34-
stderr=subprocess.PIPE, close_fds=True)
35-
36-
line = res.stdout.readline().decode('ascii')
37-
38-
if not line:
39-
board_cfg_lib.print_yel("'{}' not found, please install it!".format(excute))
40-
sys.exit(1)
41-
42-
if excute == "git":
43-
res = subprocess.Popen("git tag -l", shell=True, stdout=subprocess.PIPE,
44-
stderr=subprocess.PIPE, close_fds=True)
45-
line = res.stdout.readline().decode("ascii")
46-
47-
if "acrn" not in line:
48-
board_cfg_lib.print_red("Run this tool in acrn-hypervisor mainline source code!")
49-
sys.exit(1)
50-
51-
for py_cache in PY_CACHES:
52-
if os.path.exists(py_cache):
53-
shutil.rmtree(py_cache)
54-
55-
56-
def gen_patch(srcs_list, board_name):
57-
"""Generate patch and apply to local source code
58-
:param srcs_list: it is a list what contains source files
59-
:param board_name: board name
28+
def main(args):
6029
"""
61-
changes = ' '.join(srcs_list)
62-
git_add = "git add {}".format(changes)
63-
subprocess.call(git_add, shell=True, stdout=subprocess.PIPE,
64-
stderr=subprocess.PIPE, close_fds=True)
65-
66-
# commit this changes
67-
git_commit = 'git commit -sm "acrn-config: config board patch for {}"'.format(board_name)
68-
subprocess.call(git_commit, shell=True, stdout=subprocess.PIPE,
69-
stderr=subprocess.PIPE, close_fds=True)
70-
71-
72-
def main(board_info_file):
73-
"""This is main function to start generate source code related with board
74-
:param board_info_file: it is a file what contains board information for script to read from
30+
This is main function to start generate source code related with board
31+
:param args: it is a command line args for the script
7532
"""
76-
board = ''
33+
err_dic = {}
7734
config_srcs = []
7835
config_dirs = []
7936

37+
(err_dic, board_info_file, scenario_info_file) = board_cfg_lib.get_param(args)
38+
if err_dic:
39+
return err_dic
40+
41+
board_cfg_lib.BOARD_INFO_FILE = board_info_file
42+
board_cfg_lib.SCENARIO_INFO_FILE = scenario_info_file
43+
board_cfg_lib.get_vm_count(scenario_info_file)
44+
8045
# get board name
81-
board = board_cfg_lib.get_board_name(board_info_file)
46+
(err_dic, board) = board_cfg_lib.get_board_name()
47+
if err_dic:
48+
return err_dic
49+
board_cfg_lib.BOARD_NAME = board
50+
51+
# check if this is the scenario config which matched board info
52+
(err_dic, status) = board_cfg_lib.is_config_file_match()
53+
if not status:
54+
err_dic['board config: Not match'] = "The board xml and scenario xml should be matched"
55+
return err_dic
8256

8357
config_dirs.append(ACRN_CONFIG + board)
8458
if board not in BOARD_NAMES:
8559
for config_dir in config_dirs:
8660
if not os.path.exists(config_dir):
8761
os.makedirs(config_dir)
8862

89-
config_pci = config_dirs[0] + '/' + GEN_FILE[3]
90-
config_board = config_dirs[0] + '/' + GEN_FILE[4]
91-
config_platform = config_dirs[0] + '/' + board + GEN_FILE[5]
63+
config_pci = config_dirs[0] + '/' + GEN_FILE[0]
64+
config_board = config_dirs[0] + '/' + GEN_FILE[1]
65+
config_platform = config_dirs[0] + '/' + board + GEN_FILE[2]
66+
config_misc_cfg = config_dirs[0] + '/' + GEN_FILE[3]
67+
config_ve820 = config_dirs[0] + '/' + GEN_FILE[4]
68+
config_board_kconfig = ACRN_CONFIG + board + GEN_FILE[5]
9269

9370
config_srcs.append(config_pci)
9471
config_srcs.append(config_board)
9572
config_srcs.append(config_platform)
73+
config_srcs.append(config_misc_cfg)
74+
config_srcs.append(config_ve820)
75+
config_srcs.append(config_board_kconfig)
9676

9777
# generate board.c
9878
with open(config_board, 'w+') as config:
99-
board_c.generate_file(config)
79+
err_dic = board_c.generate_file(config)
80+
if err_dic:
81+
return err_dic
10082

10183
# generate pci_devices.h
10284
with open(config_pci, 'w+') as config:
@@ -106,36 +88,61 @@ def main(board_info_file):
10688
with open(config_platform, 'w+') as config:
10789
acpi_platform_h.generate_file(config, ACRN_DEFAULT_PLATFORM)
10890

109-
# move changes to patch, and apply to the source code
110-
gen_patch(config_srcs, board)
91+
# generate acpi_platform.h
92+
with open(config_ve820, 'w+') as config:
93+
err_dic = ve820_c.generate_file(config)
94+
if err_dic:
95+
return err_dic
96+
97+
# generate acpi_platform.h
98+
with open(config_misc_cfg, 'w+') as config:
99+
err_dic = misc_cfg_h.generate_file(config)
100+
if err_dic:
101+
return err_dic
111102

103+
# generate new board_name.config
112104
if board not in BOARD_NAMES:
105+
with open(config_board_kconfig, 'w+') as config:
106+
err_dic = new_board_kconfig.generate_file(config)
107+
if err_dic:
108+
return err_dic
109+
110+
# move changes to patch, and apply to the source code
111+
err_dic = board_cfg_lib.gen_patch(config_srcs, board)
112+
113+
if board not in BOARD_NAMES and not err_dic:
113114
print("Config patch for NEW board {} is committed successfully!".format(board))
114-
else:
115+
elif not err_dic:
115116
print("Config patch for {} is committed successfully!".format(board))
117+
else:
118+
print("Config patch for {} is failed".format(board))
116119

120+
return err_dic
117121

118-
def usage():
119-
"""This is usage for how to use this tool"""
120-
print("usage= [h] --board <board_info_file>'")
121-
print('board_info_file, : file name of the board info"')
122-
sys.exit(1)
123122

123+
def ui_entry_api(board_info,scenario_info):
124124

125-
if __name__ == '__main__':
126-
prepare()
125+
arg_list = ['board_cfg_gen.py', '--board', board_info, '--scenario', scenario_info]
127126

128-
ARGS = sys.argv[1:]
127+
err_dic = board_cfg_lib.prepare()
128+
if err_dic:
129+
return err_dic
129130

130-
if ARGS[0] != '--board':
131-
usage()
132-
sys.exit(1)
131+
err_dic = main(arg_list)
132+
133+
return err_dic
133134

134-
BOARD_INFO_FILE = ARGS[1]
135-
if not os.path.exists(BOARD_INFO_FILE):
136-
board_cfg_lib.print_red("{} is not exist!".format(BOARD_INFO_FILE))
137-
sys.exit(1)
138135

139-
board_cfg_lib.BOARD_INFO_FILE = BOARD_INFO_FILE
136+
if __name__ == '__main__':
137+
138+
err_dic = board_cfg_lib.prepare()
139+
if err_dic:
140+
for err_k, err_v in err_dic.items():
141+
board_cfg_lib.print_red("{}: {}".format(err_k, err_v), err=True)
142+
sys.exit(1)
140143

141-
main(BOARD_INFO_FILE)
144+
ARGS = sys.argv
145+
err_dic = main(ARGS)
146+
if err_dic:
147+
for err_k, err_v in err_dic.items():
148+
board_cfg_lib.print_red("{}: {}".format(err_k, err_v), err=True)

0 commit comments

Comments
 (0)