Skip to content

Commit edc145c

Browse files
committed
Some enhancement for the command mode
This commit adds option to display configuration in command mode. Currently only some of the global configuration are added. Others could be added later when needed. RM #4670238 Signed-off-by: Liming Sun <[email protected]>
1 parent e68c043 commit edc145c

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

man/rshim.8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ Run rshim as command line rather than as driver. The following sub-commands are
100100
-g, --get-debug
101101
Get the current debug setting.
102102

103+
-p, --get-config <NAME | all>
104+
Get configuration value by name or use 'all' to see the list.
105+
103106
-s, set-debug <0 | 1>
104107
Set the debug setting.
105108
.in

src/rshim.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ char *rshim_static_dev_name;
220220
/* Default configuration file. */
221221
const char *rshim_cfg_file = DEFAULT_RSHIM_CONFIG_FILE;
222222
static int rshim_display_level;
223-
static int rshim_boot_timeout = 300;
223+
int rshim_boot_timeout = 300;
224224
int rshim_drop_mode = -1;
225225
int rshim_usb_reset_delay = 1;
226226
bool rshim_has_usb_reset_delay;
@@ -3303,6 +3303,7 @@ static void print_help(void)
33033303
printf(" -b, --backend backend name (usb, pcie or pcie-lf)\n");
33043304
printf(" -c, --cmdmode run in command line mode\n");
33053305
printf(" -g, --get-debug get debug mode\n");
3306+
printf(" -p, --get-config <NAME | all> get config value\n");
33063307
printf(" -s, --set-debug <0 | 1> set debug mode\n");
33073308
printf(" -d, --device device to attach\n");
33083309
printf(" -f, --foreground run in foreground\n");
@@ -3316,14 +3317,15 @@ static void print_help(void)
33163317

33173318
int main(int argc, char *argv[])
33183319
{
3319-
static const char short_options[] = "b:cd:fgFhi:l:nsv";
3320+
static const char short_options[] = "b:cd:fgFhi:l:np:sv";
33203321
static struct option long_options[] = {
33213322
{ "backend", required_argument, NULL, 'b' },
33223323
{ "cmdmode", no_argument, NULL, 'c' },
33233324
{ "device", required_argument, NULL, 'd' },
33243325
{ "foreground", no_argument, NULL, 'f' },
33253326
{ "force", no_argument, NULL, 'F' },
33263327
{ "get-debug", no_argument, NULL, 'g' },
3328+
{ "get-config", required_argument, NULL, 'p' },
33273329
{ "help", no_argument, NULL, 'h' },
33283330
{ "index", required_argument, NULL, 'i' },
33293331
{ "log-level", required_argument, NULL, 'l' },

src/rshim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern int rshim_log_level;
4141
extern bool rshim_daemon_mode;
4242
extern int rshim_drop_mode;
4343
extern bool rshim_force_mode;
44+
extern int rshim_boot_timeout;
4445
extern int rshim_usb_timeout;
4546
extern int rshim_usb_reset_delay;
4647
extern bool rshim_has_usb_reset_delay;

src/rshim_cmdmode.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,40 @@ static int rshim_getset_debug(rshim_backend_t *bd, bool get, uint32_t *setting)
4242
return 0;
4343
}
4444

45+
static int dump_config(char *name)
46+
{
47+
if (!name) {
48+
printf("Invalid command\n");
49+
return -EINVAL;
50+
}
51+
52+
if (!strcmp(name, "USB_TIMEOUT")) {
53+
printf("%d\n", rshim_usb_timeout);
54+
} else if (!strcmp(name, "BOOT_TIMEOUT")) {
55+
printf("%d\n", rshim_boot_timeout);
56+
} else if (!strcmp(name, "PCIE_RESET_DELAY")) {
57+
printf("%d\n", rshim_pcie_reset_delay);
58+
} else if (!strcmp(name, "USB_RESET_DELAY")) {
59+
printf("%d\n", rshim_usb_reset_delay);
60+
} else if (!strcmp(name, "all")) {
61+
printf("BOOT_TIMEOUT %d\n", rshim_boot_timeout);
62+
printf("PCIE_RESET_DELAY %d\n", rshim_pcie_reset_delay);
63+
printf("USB_RESET_DELAY %d\n", rshim_usb_reset_delay);
64+
printf("USB_TIMEOUT %d\n", rshim_usb_timeout);
65+
} else {
66+
printf("Invalid command\n");
67+
return -EINVAL;
68+
}
69+
70+
return 0;
71+
}
72+
4573
int rshim_cmdmode_run(int argc, char *argv[])
4674
{
47-
static const char short_options[] = "cgs:";
75+
static const char short_options[] = "cgp:s:";
4876
static struct option long_options[] = {
4977
{ "get-debug", no_argument, NULL, 'g' },
78+
{ "get-config", required_argument, NULL, 'p' },
5079
{ "set-debug", required_argument, NULL, 's' },
5180
{ NULL, 0, NULL, 0 }
5281
};
@@ -82,6 +111,10 @@ int rshim_cmdmode_run(int argc, char *argv[])
82111
printf("0x%x\n", setting);
83112
break;
84113

114+
case 'p':
115+
rc = dump_config(optarg);
116+
break;
117+
85118
case 's':
86119
setting = atoi(optarg);
87120
rc = rshim_getset_debug(bd, false, &setting);

0 commit comments

Comments
 (0)