Skip to content

Commit aee3bc3

Browse files
Wei Liuwenlingz
authored andcommitted
acrn-config: enable item check for launch config tool
1. enable item check for acrn-dm args which set from webUI input. 2. remove 'cpu_num' tag from launch config xml. v1-v2: 1). add method to check 'cpu_num'/'mem_size' in config xml. v2-v3: 1). as 'vcpu_num' configured in scenario, the parameter for acrn-dm is no longer needed, remove 'cpu_num' tag and its handler from launch config. 2). add 'poweroff_channel' tag for generic config. Tracked-On: #3811 Signed-off-by: Wei Liu <weix.w.liu@intel.com> Acked-by: Victor Sun <victor.sun@intel.com>
1 parent 98dc755 commit aee3bc3

28 files changed

+123
-60
lines changed

misc/acrn-config/launch_config/com.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def tap_uos_net(names, vmid, config):
2323

2424
if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"):
2525
if board_name in ("apl-mrb", "apl-up2"):
26-
print('if [ ! -f "/data/$5/$5.img" ]; then', file=config)
27-
print(' echo "no /data/$5/$5.img, exit"', file=config)
26+
print('if [ ! -f "/data/$3/$3.img" ]; then', file=config)
27+
print(' echo "no /data/$3/$3.img, exit"', file=config)
2828
print(" exit", file=config)
2929
print("fi", file=config)
3030
print("", file=config)
@@ -40,7 +40,7 @@ def tap_uos_net(names, vmid, config):
4040
if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"):
4141
if board_name in ("apl-mrb", "apl-up2"):
4242
print("# create a unique tap device for each VM", file=config)
43-
print("tap=tap_$6", file=config)
43+
print("tap=tap_$4", file=config)
4444
print('tap_exist=$(ip a | grep "$tap" | awk \'{print $1}\')', file=config)
4545
print('if [ "$tap_exist"x != "x" ]; then', file=config)
4646
print(' echo "tap device existed, reuse $tap"', file=config)
@@ -155,7 +155,7 @@ def boot_image_type(args, vmid, config):
155155
return
156156

157157
print('boot_dev_flag=",b"', file=config)
158-
print("if [ $7 == 1 ];then", file=config)
158+
print("if [ $5 == 1 ];then", file=config)
159159
print(' boot_image_option="--vsbl /usr/share/acrn/bios/VSBL_debug.bin"', file=config)
160160
print("else", file=config)
161161
print(' boot_image_option="--vsbl /usr/share/acrn/bios/VSBL.bin"', file=config)
@@ -177,11 +177,9 @@ def interrupt_storm(names, vmid, config):
177177

178178
def gvt_arg_set(uos_type, config):
179179

180-
if uos_type not in ('CLEARLINUX', 'ANDROID', 'ALIOS'):
180+
if uos_type not in ('CLEARLINUX', 'ANDROID', 'ALIOS', 'WINDOWS'):
181181
return
182-
print("GVT_args=$3", file=config)
183-
print('boot_GVT_option=" -s 0:2:0,pci-gvt -G "', file=config)
184-
print("", file=config)
182+
print(' -s 2,pci-gvt -G "$2" \\', file=config)
185183

186184

187185
def log_level_set(uos_type, config):
@@ -246,8 +244,8 @@ def function_help(config):
246244

247245

248246
def uos_launch(names, args, vmid, config):
247+
249248
gvt_args = args['gvt_args'][vmid]
250-
cpu_num = int(args['cpu_num'][vmid])
251249
uos_type = names['uos_types'][vmid]
252250
launch_uos = '_'.join(uos_type.lower().split())
253251

@@ -256,39 +254,40 @@ def uos_launch(names, args, vmid, config):
256254
print("", file=config)
257255
print("case $launch_type in", file=config)
258256
print(' 1) echo "Launch clearlinux UOS"', file=config)
259-
print(' launch_clearlinux 1 {} "{}" 0x070F00 clearlinux "LaaG" $debug'.format(cpu_num, gvt_args), file=config)
257+
print(' launch_clearlinux 1 "{}" clearlinux "LaaG" $debug'.format(gvt_args), file=config)
260258
print(" ;;", file=config)
261259
print(' 2) echo "Launch android UOS"', file=config)
262-
print(' launch_android 1 {} "{}" 0x070F00 android "AaaG" $debug'.format(cpu_num, gvt_args), file=config)
260+
print(' launch_android 1 "{}" android "AaaG" $debug'.format(gvt_args), file=config)
263261
print(" ;;", file=config)
264262
print(' 4) echo "Launch two clearlinux UOSs"', file=config)
265-
print(' launch_clearlinux 1 {} "{}" 0x00000C clearlinux "L1aaG" $debug &'.format(cpu_num, gvt_args), file=config)
263+
print(' launch_clearlinux 1 "{}" clearlinux "L1aaG" $debug &'.format(gvt_args), file=config)
266264
print(" sleep 5", file=config)
267-
print(' launch_clearlinux 2 {} "{}" 0x070F00 clearlinux_dup "L2aaG" $debug'.format(cpu_num, gvt_args), file=config)
265+
print(' launch_clearlinux 2 "{}" clearlinux_dup "L2aaG" $debug'.format(gvt_args), file=config)
268266
print(" ;;", file=config)
269267
print(' 5) echo "Launch alios UOS"', file=config)
270-
print(' launch_alios 1 {} "{}" 0x070F00 alios "AliaaG" $debug'.format(cpu_num, gvt_args), file=config)
268+
print(' launch_alios 1 "{}" alios "AliaaG" $debug'.format(gvt_args), file=config)
269+
271270
print(" ;;", file=config)
272271
print("esac", file=config)
273272
print("", file=config)
274273
print("umount /data", file=config)
275274

276275
if uos_type not in ("CLEARLINUX", "ANDROID", "ALIOS"):
277276
if uos_type == "VXWORKS":
278-
print("launch_{} 1 {}".format(launch_uos, cpu_num), file=config)
277+
print("launch_{} 1".format(launch_uos), file=config)
279278
if uos_type == "PREEMPT-RT LINUX":
280-
print("launch_{} {}".format(launch_uos, cpu_num), file=config)
279+
print("launch_{}".format(launch_uos), file=config)
281280
if uos_type == "WINDOWS":
282-
print('launch_{} 1 {} "{}"'.format(launch_uos, cpu_num, gvt_args), file=config)
281+
print('launch_{} 1 "{}"'.format(launch_uos, gvt_args), file=config)
283282
if uos_type == "ZEPHYR":
284-
print("launch_{} 1 {}".format(launch_uos, cpu_num), file=config)
283+
print("launch_{} 1".format(launch_uos), file=config)
285284

286285
if is_nuc_clr(names, vmid):
287286
print('if [ "$1" = "-C" ];then', file=config)
288287
print(' echo "runc_container"', file=config)
289288
print(" run_container", file=config)
290289
print("else", file=config)
291-
print(' launch_{} 1 {} "{}" 0x070F00'.format(launch_uos, cpu_num, gvt_args), file=config)
290+
print(' launch_{} 1 "{}"'.format(launch_uos, gvt_args), file=config)
292291
print("fi", file=config)
293292

294293

@@ -421,7 +420,7 @@ def dm_arg_set(names, sel, dm, vmid, config):
421420
sos_vmid = launch_cfg_lib.get_sos_vmid()
422421

423422
# clearlinux/android/alios
424-
dm_str = 'acrn-dm -A -m $mem_size $boot_GVT_option"$GVT_args" -s 0:0,hostbridge -s 1:0,lpc -U {}'.format(scenario_uuid[vmid + sos_vmid])
423+
dm_str = 'acrn-dm -A -m $mem_size -s 0:0,hostbridge -s 1:0,lpc -U {}'.format(scenario_uuid[vmid + sos_vmid])
425424
if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"):
426425
if uos_type == "CLEARLINUX":
427426
print("{} \\".format(dm_str), file=config)
@@ -474,10 +473,12 @@ def dm_arg_set(names, sel, dm, vmid, config):
474473
# windows
475474
if uos_type == "WINDOWS":
476475
print("acrn-dm -A -m $mem_size -s 0:0,hostbridge -s 1:0,lpc -U {} \\".format(scenario_uuid[vmid + sos_vmid]), file=config)
477-
print(' -s 2,pci-gvt -G "$3" \\', file=config)
478476
print(" -s {},virtio-blk,./win10-ltsc.img \\".format(launch_cfg_lib.virtual_dev_slot("virtio-blk")), file=config)
479477

480-
# vbootloader of ovmf
478+
# GVT args set
479+
gvt_arg_set(uos_type, config)
480+
481+
# vbootloader of ovmf
481482
#if uos_type != "PREEMPT-RT LINUX" and dm['vbootloader'][vmid] == "ovmf":
482483
if dm['vbootloader'][vmid] == "ovmf":
483484
print(" --ovmf /usr/share/acrn/bios/OVMF.fd \\", file=config)
@@ -507,7 +508,7 @@ def dm_arg_set(names, sel, dm, vmid, config):
507508
print(" $intr_storm_monitor \\", file=config)
508509
if dm['vbootloader'][vmid] == "vsbl":
509510
print(" $boot_image_option \\",file=config)
510-
print(" -s {},virtio-blk$boot_dev_flag,/data/$5/$5.img \\".format(launch_cfg_lib.virtual_dev_slot("virtio-blk")), file=config)
511+
print(" -s {},virtio-blk$boot_dev_flag,/data/$3/$3.img \\".format(launch_cfg_lib.virtual_dev_slot("virtio-blk")), file=config)
511512
print(" -s {},xhci,1-1:1-2:1-3:2-1:2-2:2-3:cap=apl \\".format(launch_cfg_lib.virtual_dev_slot("xhci")), file=config)
512513
else:
513514
print(" -s {},virtio-blk,/home/clear/uos/uos.img \\".format(launch_cfg_lib.virtual_dev_slot("virtio-blk")), file=config)
@@ -540,7 +541,6 @@ def gen(names, pt_sel, dm, vmid, config):
540541
delay_use_usb_storage(uos_type, config)
541542
mem_size_set(names, dm, vmid, config)
542543
interrupt_storm(names, vmid, config)
543-
gvt_arg_set(uos_type, config)
544544
log_level_set(uos_type, config)
545545

546546
# gen acrn-dm args

misc/acrn-config/launch_config/launch_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def __init__(self, board_info, scenario_info, launch_info):
1616
def get_args(self):
1717
self.args["uos_type"] = launch_cfg_lib.get_sub_tree_tag(self.launch_info, "uos_type")
1818
self.args["rtos_type"] = launch_cfg_lib.get_sub_tree_tag(self.launch_info, "rtos_type")
19-
self.args["cpu_num"] = launch_cfg_lib.get_sub_tree_tag(self.launch_info, "cpu_num")
2019
self.args["mem_size"] = launch_cfg_lib.get_sub_tree_tag(self.launch_info, "mem_size")
2120
self.args["gvt_args"] = launch_cfg_lib.get_sub_tree_tag(self.launch_info, "gvt_args")
2221
self.args["rootfs_dev"] = launch_cfg_lib.get_sub_tree_tag(self.launch_info, "rootfs_dev")
@@ -27,6 +26,7 @@ def check_item(self):
2726
rootfs = launch_cfg_lib.get_rootdev_info(self.board_info)
2827
launch_cfg_lib.args_aval_check(self.args["uos_type"], "uos_type", launch_cfg_lib.UOS_TYPES)
2928
launch_cfg_lib.args_aval_check(self.args["rtos_type"], "rtos_type", launch_cfg_lib.RTOS_TYPE)
29+
launch_cfg_lib.mem_size_check(self.args["mem_size"], "mem_size")
3030
launch_cfg_lib.args_aval_check(self.args["gvt_args"], "gvt_args", launch_cfg_lib.GVT_ARGS)
3131
launch_cfg_lib.args_aval_check(self.args["vbootloader"], "vbootloader", launch_cfg_lib.BOOT_TYPE)
3232
launch_cfg_lib.args_aval_check(self.args["console_type"], "console_type", launch_cfg_lib.REDIRECT_CONSOLE)

misc/acrn-config/library/launch_cfg_lib.py

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,22 +441,95 @@ def pt_devs_check(bdf_list, vpid_list, item):
441441
i_cnt += 1
442442

443443

444-
def args_aval_check(arg_list, item, avl_list):
444+
def empty_err(i_cnt, item):
445+
"""
446+
add empty error message into ERR_LIST
447+
:param i_cnt: the launch vm index from config xml
448+
:param item: the item of tag from config xml
449+
:return: None
450+
"""
451+
key = "uos,id={},{}".format(i_cnt, item)
452+
ERR_LIST[key] = "The parameter should not be empty"
445453

446-
# allow args of dm is empty in launch xml
447-
return
448-
err_dic = {}
454+
455+
def args_aval_check(arg_list, item, avl_list):
456+
"""
457+
check arguments from config xml are available and validate
458+
:param arg_list: the list of arguments from config xml
459+
:param item: the item of tag from config xml
460+
:param avl_list: available argument which are allowed to chose
461+
:return: None
462+
"""
463+
# args should be set into launch xml from webUI
449464
i_cnt = 1
450465
for arg_str in arg_list.values():
451-
if arg_str == None or not arg_str:
452-
key = "uos,id={},{}".format(i_cnt, item)
453-
err_dic[key] = "The parameter should not be empty"
466+
if arg_str == None or not arg_str.strip():
467+
empty_err(i_cnt, item)
468+
i_cnt += 1
469+
continue
454470

455471
if arg_str not in avl_list:
456472
key = "uos,id={},{}".format(i_cnt, item)
457473
ERR_LIST[key] = "The {} is invalidate".format(item)
458-
if err_dic:
459-
ERR_LIST.update(err_dic)
474+
i_cnt += 1
475+
476+
477+
def get_cpu_processor_num():
478+
"""
479+
get cpu processor number from config file which is dumped from native board
480+
:return: integer number of cpu processor
481+
"""
482+
cpu_lines = get_info(BOARD_INFO_FILE, "<CPU_PROCESSOR_INFO>", "</CPU_PROCESSOR_INFO>")
483+
484+
for cpu_line in cpu_lines:
485+
cpu_processor_num = len(cpu_line.split(','))
486+
487+
return cpu_processor_num
488+
489+
490+
def get_total_mem():
491+
"""
492+
get total memory size from config file which is dumped from native board
493+
:return: integer number of total memory size, Unit: MByte
494+
"""
495+
scale_to_mb = 1
496+
total_mem_mb = scale_to_mb
497+
mem_lines = get_info(BOARD_INFO_FILE, "<TOTAL_MEM_INFO>", "</TOTAL_MEM_INFO>")
498+
for mem_line in mem_lines:
499+
mem_info_list = mem_line.split()
500+
501+
if len(mem_info_list) <= 1:
502+
return total_mem_mb
503+
504+
if mem_info_list[1] == "kB":
505+
scale_to_mb = 1024
506+
507+
total_mem_mb = int(mem_info_list[0]) / scale_to_mb
508+
return total_mem_mb
509+
510+
511+
def mem_size_check(arg_list, item):
512+
"""
513+
check memory size list which are set from webUI
514+
:param arg_list: the list of arguments from config xml
515+
:param item: the item of tag from config xml
516+
:return: None
517+
"""
518+
# get total memory information
519+
total_mem_mb = get_total_mem()
520+
521+
# available check
522+
i_cnt = 1
523+
for arg_str in arg_list.values():
524+
if arg_str == None or not arg_str.strip():
525+
empty_err(i_cnt, item)
526+
i_cnt += 1
527+
continue
528+
529+
mem_size_set = int(arg_str.strip())
530+
if mem_size_set > total_mem_mb:
531+
key = "uos,id={},{}".format(i_cnt, item)
532+
ERR_LIST[key] = "{}MB should be less than total memory {}MB".format(item)
460533
i_cnt += 1
461534

462535

misc/acrn-config/xmls/config-xmls/apl-mrb/sdc_launch_1uos_aaag.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<uos id="1">
33
<uos_type desc="UOS type">ANDROID</uos_type>
44
<rtos_type desc="UOS Realtime capability">no</rtos_type>
5-
<cpu_num desc="max cpu number for vm">2</cpu_num>
65
<mem_size desc="UOS memory size in MByte">2048</mem_size>
76
<gvt_args desc="GVT argument for the vm">64 448 8</gvt_args>
87
<vbootloader desc="virtual bootloader method" readonly="true">ovmf</vbootloader>

misc/acrn-config/xmls/config-xmls/apl-mrb/sdc_launch_1uos_aliaag.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<uos id="1">
33
<uos_type desc="UOS type">ALIOS</uos_type>
44
<rtos_type desc="UOS Realtime capability">no</rtos_type>
5-
<cpu_num desc="max cpu number for vm">2</cpu_num>
65
<mem_size desc="UOS memory size in MByte">2048</mem_size>
76
<gvt_args desc="GVT argument for the vm">64 448 8</gvt_args>
87
<vbootloader desc="virtual bootloader method" readonly="true">ovmf</vbootloader>

misc/acrn-config/xmls/config-xmls/apl-mrb/sdc_launch_1uos_laag.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<uos id="1">
33
<uos_type desc="UOS type">CLEARLINUX</uos_type>
44
<rtos_type desc="UOS Realtime capability">no</rtos_type>
5-
<cpu_num desc="max cpu number for the vm">3</cpu_num>
65
<mem_size desc="UOS memory size in MByte">2048</mem_size>
76
<gvt_args desc="GVT argument for the vm">64 448 8</gvt_args>
87
<vbootloader desc="virtual bootloader method" readonly="true">ovmf</vbootloader>

misc/acrn-config/xmls/config-xmls/apl-up2-n3350/sdc_launch_1uos_laag.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<uos id="1">
33
<uos_type desc="UOS type">CLEARLINUX</uos_type>
44
<rtos_type desc="UOS Realtime capability">no</rtos_type>
5-
<cpu_num desc="max cpu number for the vm">1</cpu_num>
65
<mem_size desc="UOS memory size in MByte">2048</mem_size>
76
<gvt_args desc="GVT argument for the vm">64 448 8</gvt_args>
87
<vbootloader desc="virtual bootloader method" readonly="true">ovmf</vbootloader>

misc/acrn-config/xmls/config-xmls/apl-up2/sdc_launch_1uos_aaag.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<uos id="1">
33
<uos_type desc="UOS type">ANDROID</uos_type>
44
<rtos_type desc="UOS Realtime capability">no</rtos_type>
5-
<cpu_num desc="max cpu number for vm">1</cpu_num>
65
<mem_size desc="UOS memory size in MByte">2048</mem_size>
76
<gvt_args desc="GVT argument for the vm">64 448 8</gvt_args>
87
<vbootloader desc="virtual bootloader method" readonly="true">ovmf</vbootloader>

misc/acrn-config/xmls/config-xmls/apl-up2/sdc_launch_1uos_laag.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<uos id="1">
33
<uos_type desc="UOS type">CLEARLINUX</uos_type>
44
<rtos_type desc="UOS Realtime capability">no</rtos_type>
5-
<cpu_num desc="max cpu number for the vm">1</cpu_num>
65
<mem_size desc="UOS memory size in MByte">2048</mem_size>
76
<gvt_args desc="GVT argument for the vm">64 448 8</gvt_args>
87
<vbootloader desc="virtual bootloader method" readonly="true">ovmf</vbootloader>

misc/acrn-config/xmls/config-xmls/generic/hybrid_launch_1uos.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<rootfs_dev desc=""></rootfs_dev>
99
<rootfs_img desc=""></rootfs_img>
1010
<console_type desc="UOS console type"></console_type>
11+
<poweroff_channel desc="the method of power off uos">
12+
</poweroff_channel>
1113

1214
<passthrough_devices>
1315
<usb_xdci desc="vm usb_xdci device"></usb_xdci>

0 commit comments

Comments
 (0)