diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index bfd6d005a..07fa87413 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -162,6 +162,7 @@ usage(int code) " -i: ioc boot parameters\n" #ifdef CONFIG_VM_CFG " --vmcfg: build-in VM configurations\n" + " --dump: show build-in VM configurations\n" #endif " --vsbl: vsbl file path\n" " --part_info: guest partition info file path\n" @@ -710,6 +711,7 @@ enum { CMD_OPT_PTDEV_NO_RESET, CMD_OPT_DEBUGEXIT, CMD_OPT_VMCFG, + CMD_OPT_DUMP, }; static struct option long_options[] = { @@ -742,6 +744,7 @@ static struct option long_options[] = { /* Following cmd option only has long option */ #ifdef CONFIG_VM_CFG {"vmcfg", required_argument, 0, CMD_OPT_VMCFG}, + {"dump", required_argument, 0, CMD_OPT_DUMP}, #endif {"vsbl", required_argument, 0, CMD_OPT_VSBL}, {"part_info", required_argument, 0, CMD_OPT_PART_INFO}, @@ -1047,6 +1050,10 @@ int main(int argc, char *argv[]) vmcfg = 1; index = atoi(optarg); break; + case CMD_OPT_DUMP: + index = atoi(optarg); + vmcfg_dump(index, long_options, optstr); + return 0; default: dm_options++; } diff --git a/devicemodel/include/vmcfg.h b/devicemodel/include/vmcfg.h index 64e27d739..186f02aee 100644 --- a/devicemodel/include/vmcfg.h +++ b/devicemodel/include/vmcfg.h @@ -6,6 +6,8 @@ #ifndef VMCFG_H #define VMCFG_H +#include + struct vmcfg_arg { char **argv; int argc; @@ -19,4 +21,5 @@ extern int num_args_buildin; extern struct vmcfg_arg mrb_vm1_args; void vmcfg_list(void); +void vmcfg_dump(int index, struct option *long_options, char *optstr); #endif diff --git a/devicemodel/vmcfg/vmcfg.c b/devicemodel/vmcfg/vmcfg.c index c0a58e3c7..bf35b764c 100644 --- a/devicemodel/vmcfg/vmcfg.c +++ b/devicemodel/vmcfg/vmcfg.c @@ -6,6 +6,7 @@ #include #include #include +#include void vmcfg_list(void) { @@ -18,6 +19,39 @@ void vmcfg_list(void) } } +void vmcfg_dump(int index, struct option *long_options, char *optstr) +{ + char **argv; + int argc; + int c, option_idx = 0; + int i = 1; + + if ((index <= 0) || (index > num_args_buildin)) { + fprintf(stderr, "%s(%d) index should be 1~%d\n", __FUNCTION__, + index, num_args_buildin); + return; + } + + if (args_buildin[index - 1]->setup) + args_buildin[index - 1]->setup(); + + argv = args_buildin[index - 1]->argv; + argc = args_buildin[index - 1]->argc; + + printf("%s build-in args:\n", argv[argc - 1]); + + optind = 0; + + while ((c = getopt_long(argc, argv, optstr, long_options, + &option_idx)) != -1) { + if (optarg) + printf("%s %s\n", argv[i], optarg); + else + printf("%s\n", argv[i]); + i = optind; + } +} + static struct vmcfg_arg *vmcfg_buildin_args[] = { #ifdef CONFIG_MRB_VM1 &mrb_vm1_args,