Skip to content

Commit 67d7292

Browse files
taoyuhongwenlingz
authored andcommitted
DM: VMcfg: support --vmcfg options
Enable --vmcfg options for acrn-dm, if --vmcfg <index> is specified, build-in VM configuration will be used, and override any other optional parameters. run 'acrn-dm --vmcfg list' to show all build-in VM configurations. run 'acrnpdm --vmcfg <index>' to launch UOS with selected config. Tracked-On: #1528 Acked-by: Yin Fengwei <fengwei.yin@intel.com> Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
1 parent 321021e commit 67d7292

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

devicemodel/core/main.c

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
#include "ioc.h"
6363
#include "pm.h"
6464
#include "atomic.h"
65+
#include "vmcfg_config.h"
66+
#include "vmcfg.h"
6567

6668
#define GUEST_NIO_PORT 0x488 /* guest upcalls via i/o port */
6769

@@ -158,6 +160,9 @@ usage(int code)
158160
" -G: GVT args: low_gm_size, high_gm_size, fence_sz\n"
159161
" -v: version\n"
160162
" -i: ioc boot parameters\n"
163+
#ifdef CONFIG_VM_CFG
164+
" --vmcfg: build-in VM configurations\n"
165+
#endif
161166
" --vsbl: vsbl file path\n"
162167
" --part_info: guest partition info file path\n"
163168
" --enable_trusty: enable trusty for guest\n"
@@ -704,6 +709,7 @@ enum {
704709
CMD_OPT_TRUSTY_ENABLE,
705710
CMD_OPT_PTDEV_NO_RESET,
706711
CMD_OPT_DEBUGEXIT,
712+
CMD_OPT_VMCFG,
707713
};
708714

709715
static struct option long_options[] = {
@@ -734,6 +740,9 @@ static struct option long_options[] = {
734740
{"help", no_argument, 0, 'h' },
735741

736742
/* Following cmd option only has long option */
743+
#ifdef CONFIG_VM_CFG
744+
{"vmcfg", required_argument, 0, CMD_OPT_VMCFG},
745+
#endif
737746
{"vsbl", required_argument, 0, CMD_OPT_VSBL},
738747
{"part_info", required_argument, 0, CMD_OPT_PART_INFO},
739748
{"enable_trusty", no_argument, 0,
@@ -744,14 +753,15 @@ static struct option long_options[] = {
744753
{0, 0, 0, 0 },
745754
};
746755

756+
static char optstr[] = "abehuwxACHIPSWYvk:r:B:p:g:c:s:m:l:U:G:i:";
757+
747758
int
748-
main(int argc, char *argv[])
759+
dm_run(int argc, char *argv[])
749760
{
750761
int c, error, gdb_port, err;
751762
int max_vcpus, mptgen, memflags;
752763
struct vmctx *ctx;
753764
size_t memsize;
754-
char *optstr;
755765
int option_idx = 0;
756766

757767
progname = basename(argv[0]);
@@ -767,7 +777,6 @@ main(int argc, char *argv[])
767777
if (signal(SIGINT, sig_handler_term) == SIG_ERR)
768778
fprintf(stderr, "cannot register handler for SIGINT\n");
769779

770-
optstr = "abhuwxACSWYvE:k:r:B:p:g:c:s:m:l:U:G:i:";
771780
while ((c = getopt_long(argc, argv, optstr, long_options,
772781
&option_idx)) != -1) {
773782
switch (c) {
@@ -1023,3 +1032,50 @@ main(int argc, char *argv[])
10231032
vm_destroy(ctx);
10241033
exit(0);
10251034
}
1035+
1036+
int main(int argc, char *argv[])
1037+
{
1038+
int c;
1039+
int option_idx = 0;
1040+
int dm_options = 0, vmcfg = 0;
1041+
int index = -1;
1042+
1043+
while ((c = getopt_long(argc, argv, optstr, long_options,
1044+
&option_idx)) != -1) {
1045+
switch (c) {
1046+
case CMD_OPT_VMCFG:
1047+
vmcfg = 1;
1048+
index = atoi(optarg);
1049+
break;
1050+
default:
1051+
dm_options++;
1052+
}
1053+
}
1054+
1055+
if (!vmcfg) {
1056+
optind = 0;
1057+
return dm_run(argc, argv);
1058+
}
1059+
1060+
if (dm_options)
1061+
fprintf(stderr, "Waring: --vmcfg override optional args\n");
1062+
1063+
if (index <= 0) {
1064+
vmcfg_list();
1065+
return -1;
1066+
}
1067+
1068+
if (index > num_args_buildin) {
1069+
fprintf(stderr, "Error: --vmcfg %d, max index is %d\n",
1070+
index, num_args_buildin);
1071+
return -1;
1072+
}
1073+
1074+
optind = 0;
1075+
index--;
1076+
args_buildin[index]->argv[0] = argv[0];
1077+
if (args_buildin[index]->setup)
1078+
args_buildin[index]->setup();
1079+
1080+
return dm_run(args_buildin[index]->argc, args_buildin[index]->argv);
1081+
}

devicemodel/include/vmcfg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ extern struct vmcfg_arg **args_buildin;
1717
extern int num_args_buildin;
1818

1919
extern struct vmcfg_arg mrb_vm1_args;
20+
21+
void vmcfg_list(void);
2022
#endif

devicemodel/vmcfg/vmcfg.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55

66
#include <vmcfg_config.h>
77
#include <vmcfg.h>
8+
#include <stdio.h>
9+
10+
void vmcfg_list(void)
11+
{
12+
int i;
13+
char *name;
14+
15+
for (i = 0; i < num_args_buildin; i++) {
16+
name = args_buildin[i]->argv[args_buildin[i]->argc - 1];
17+
printf("%d: %s\n", i + 1, name);
18+
}
19+
}
820

921
static struct vmcfg_arg *vmcfg_buildin_args[] = {
1022
#ifdef CONFIG_MRB_VM1

0 commit comments

Comments
 (0)