6
6
7
7
import os
8
8
import sys
9
- import shutil
10
- import subprocess
9
+ sys .path .append (os .path .join (os .path .dirname (os .path .abspath (__file__ )), '..' , 'library' ))
11
10
import board_cfg_lib
12
11
import board_c
13
12
import pci_devices_h
14
13
import acpi_platform_h
14
+ import misc_cfg_h
15
+ import ve820_c
16
+ import new_board_kconfig
15
17
16
- ACRN_PATH = "../../../"
18
+ ACRN_PATH = board_cfg_lib . SOURCE_ROOT_DIR
17
19
ACRN_CONFIG = ACRN_PATH + "hypervisor/arch/x86/configs/"
18
20
19
21
BOARD_NAMES = ['apl-mrb' , 'apl-nuc' , 'apl-up2' , 'dnv-cb2' , 'nuc6cayh' ,
20
22
'nuc7i7dnb' , 'kbl-nuc-i7' , 'icl-rvp' ]
21
23
22
24
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" ]
25
26
26
- PY_CACHES = ["__pycache__" , "board_config/__pycache__" ]
27
- BIN_LIST = ['git' ]
28
27
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 ):
60
29
"""
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
75
32
"""
76
- board = ''
33
+ err_dic = {}
77
34
config_srcs = []
78
35
config_dirs = []
79
36
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
+
80
45
# 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
82
56
83
57
config_dirs .append (ACRN_CONFIG + board )
84
58
if board not in BOARD_NAMES :
85
59
for config_dir in config_dirs :
86
60
if not os .path .exists (config_dir ):
87
61
os .makedirs (config_dir )
88
62
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 ]
92
69
93
70
config_srcs .append (config_pci )
94
71
config_srcs .append (config_board )
95
72
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 )
96
76
97
77
# generate board.c
98
78
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
100
82
101
83
# generate pci_devices.h
102
84
with open (config_pci , 'w+' ) as config :
@@ -106,36 +88,61 @@ def main(board_info_file):
106
88
with open (config_platform , 'w+' ) as config :
107
89
acpi_platform_h .generate_file (config , ACRN_DEFAULT_PLATFORM )
108
90
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
111
102
103
+ # generate new board_name.config
112
104
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 :
113
114
print ("Config patch for NEW board {} is committed successfully!" .format (board ))
114
- else :
115
+ elif not err_dic :
115
116
print ("Config patch for {} is committed successfully!" .format (board ))
117
+ else :
118
+ print ("Config patch for {} is failed" .format (board ))
116
119
120
+ return err_dic
117
121
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 )
123
122
123
+ def ui_entry_api (board_info ,scenario_info ):
124
124
125
- if __name__ == '__main__' :
126
- prepare ()
125
+ arg_list = ['board_cfg_gen.py' , '--board' , board_info , '--scenario' , scenario_info ]
127
126
128
- ARGS = sys .argv [1 :]
127
+ err_dic = board_cfg_lib .prepare ()
128
+ if err_dic :
129
+ return err_dic
129
130
130
- if ARGS [ 0 ] != '--board' :
131
- usage ()
132
- sys . exit ( 1 )
131
+ err_dic = main ( arg_list )
132
+
133
+ return err_dic
133
134
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 )
138
135
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 )
140
143
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