summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-11-23 11:59:46 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-11-23 12:04:49 +0100
commit834527a5f9bfa378647f1602a41742a01b5a1b18 (patch)
tree8000c11db72f0f9c1e7b92e854be01bc292af16b
parent1c2c4246a9914bfdf234c6c636abcd27d9d3975c (diff)
downloadbarebox-834527a5f9bfa378647f1602a41742a01b5a1b18.tar.gz
nv: add device parameter overwrites to completion list
nv variables in the form dev.<devname>.* can be used to make device parameters persistent. Add these to the completion list to make setting these variables more convenient. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--commands/global.c2
-rw-r--r--commands/nv.c2
-rw-r--r--common/globalvar.c33
-rw-r--r--include/globalvar.h3
4 files changed, 35 insertions, 5 deletions
diff --git a/commands/global.c b/commands/global.c
index fc68716..c66bf6e 100644
--- a/commands/global.c
+++ b/commands/global.c
@@ -78,5 +78,5 @@ BAREBOX_CMD_START(global)
BAREBOX_CMD_OPTS("[-r] VAR[=VALUE] ...")
BAREBOX_CMD_GROUP(CMD_GRP_ENV)
BAREBOX_CMD_HELP(cmd_global_help)
- BAREBOX_CMD_COMPLETE(nv_global_complete)
+ BAREBOX_CMD_COMPLETE(global_complete)
BAREBOX_CMD_END
diff --git a/commands/nv.c b/commands/nv.c
index 51b855e..01c25a1 100644
--- a/commands/nv.c
+++ b/commands/nv.c
@@ -104,5 +104,5 @@ BAREBOX_CMD_START(nv)
BAREBOX_CMD_OPTS("[-r] VAR[=VALUE] ...")
BAREBOX_CMD_GROUP(CMD_GRP_ENV)
BAREBOX_CMD_HELP(cmd_nv_help)
- BAREBOX_CMD_COMPLETE(nv_global_complete)
+ BAREBOX_CMD_COMPLETE(nv_complete)
BAREBOX_CMD_END
diff --git a/common/globalvar.c b/common/globalvar.c
index 1db6bd9..29d158e 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -645,10 +645,39 @@ static int nv_global_param_complete(struct device_d *dev, struct string_list *sl
return 0;
}
-int nv_global_complete(struct string_list *sl, char *instr)
+int nv_complete(struct string_list *sl, char *instr)
+{
+ struct device_d *dev;
+ struct param_d *param;
+ char *str;
+ int len;
+
+ nv_global_param_complete(&global_device, sl, instr, 0);
+
+ len = strlen(instr);
+
+ if (strncmp(instr, "dev.", min_t(int, len, 4)))
+ return 0;
+
+ for_each_device(dev) {
+ if (dev == &global_device || dev == &nv_device)
+ continue;
+
+ list_for_each_entry(param, &dev->parameters, list) {
+ str = basprintf("dev.%s.%s=", dev_name(dev), param->name);
+ if (strncmp(instr, str, len))
+ free(str);
+ else
+ string_list_add(sl, str);
+ }
+ }
+
+ return 0;
+}
+
+int global_complete(struct string_list *sl, char *instr)
{
nv_global_param_complete(&global_device, sl, instr, 0);
- nv_global_param_complete(&nv_device, sl, instr, 0);
return 0;
}
diff --git a/include/globalvar.h b/include/globalvar.h
index df43f1f..67391e2 100644
--- a/include/globalvar.h
+++ b/include/globalvar.h
@@ -117,6 +117,7 @@ static inline void dev_param_init_from_nv(struct device_d *dev, const char *name
void nv_var_set_clean(void);
int nvvar_save(void);
-int nv_global_complete(struct string_list *sl, char *instr);
+int nv_complete(struct string_list *sl, char *instr);
+int global_complete(struct string_list *sl, char *instr);
#endif /* __GLOBALVAR_H */