* [PATCH 2/4] global: Make 'global' command behaviour consistent to 'nv'
2016-09-22 8:11 [PATCH 1/4] globalvar: Allow to remove multiple globalvars using wildcards Sascha Hauer
@ 2016-09-22 8:11 ` Sascha Hauer
2016-09-22 8:11 ` [PATCH 3/4] nv: simplify nvvar_add Sascha Hauer
2016-09-22 8:11 ` [PATCH 4/4] globalvar: Also create globalvars from for nonvolatile device vars Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2016-09-22 8:11 UTC (permalink / raw)
To: Barebox List
The 'nv' command can add/remove multiple variables. Implement that
for the 'global' command aswell. Also with the 'nv' command the -r
option is for removal of variables, not for "set match". Looking at
the users of "global -r" the only user uses the command for removal
of variables and not for "Setting multiple variables to the same value"
as stated in the command help text. Let "global -r" remove variables
aswell.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/at91sam9m10ihd/env/boot/android | 2 +-
commands/global.c | 35 ++++++++++++-------------
2 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/arch/arm/boards/at91sam9m10ihd/env/boot/android b/arch/arm/boards/at91sam9m10ihd/env/boot/android
index 8492e41..ce5aa32 100644
--- a/arch/arm/boards/at91sam9m10ihd/env/boot/android
+++ b/arch/arm/boards/at91sam9m10ihd/env/boot/android
@@ -3,4 +3,4 @@
global.bootm.image="/dev/nand0.kernel.bb"
global.linux.bootargs.dyn.root="root=/dev/mtdblock1 rootfstype=jffs2 rw init=/init rootdelay=1"
# clean the mtdparts otherwise android does not boot
-global -r linux.mtdparts.
+global -r "linux.mtdparts.*"
diff --git a/commands/global.c b/commands/global.c
index 581913d..d21b829 100644
--- a/commands/global.c
+++ b/commands/global.c
@@ -25,14 +25,14 @@
static int do_global(int argc, char *argv[])
{
- int opt;
- int do_set_match = 0;
+ int opt, i;
+ int do_remove = 0;
char *value;
while ((opt = getopt(argc, argv, "r")) > 0) {
switch (opt) {
case 'r':
- do_set_match = 1;
+ do_remove = 1;
break;
}
}
@@ -45,37 +45,36 @@ static int do_global(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (argc != 1)
+ if (argc < 1)
return COMMAND_ERROR_USAGE;
- value = strchr(argv[0], '=');
- if (value) {
- *value = 0;
- value++;
- }
-
- if (do_set_match) {
- if (!value)
- value = "";
+ for (i = 0; i < argc; i++) {
+ value = strchr(argv[i], '=');
+ if (value) {
+ *value = 0;
+ value++;
+ }
- globalvar_set_match(argv[0], value);
- return 0;
+ if (do_remove)
+ globalvar_remove(argv[i]);
+ else
+ globalvar_add_simple(argv[i], value);
}
- return globalvar_add_simple(argv[0], value);
+ return 0;
}
BAREBOX_CMD_HELP_START(global)
BAREBOX_CMD_HELP_TEXT("Add a new global variable named VAR, optionally set to VALUE.")
BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("Options:")
-BAREBOX_CMD_HELP_OPT("-r", "set value of all global variables beginning with 'match'")
+BAREBOX_CMD_HELP_OPT("-r", "Remove globalvars")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(global)
.cmd = do_global,
BAREBOX_CMD_DESC("create or set global variables")
- BAREBOX_CMD_OPTS("[-r] VAR[=VALUE]")
+ BAREBOX_CMD_OPTS("[-r] VAR[=VALUE] ...")
BAREBOX_CMD_GROUP(CMD_GRP_ENV)
BAREBOX_CMD_HELP(cmd_global_help)
BAREBOX_CMD_END
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/4] nv: simplify nvvar_add
2016-09-22 8:11 [PATCH 1/4] globalvar: Allow to remove multiple globalvars using wildcards Sascha Hauer
2016-09-22 8:11 ` [PATCH 2/4] global: Make 'global' command behaviour consistent to 'nv' Sascha Hauer
@ 2016-09-22 8:11 ` Sascha Hauer
2016-09-22 8:11 ` [PATCH 4/4] globalvar: Also create globalvars from for nonvolatile device vars Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2016-09-22 8:11 UTC (permalink / raw)
To: Barebox List
We do not need to have an extra code path when the variable already
exists, instead setting an existing variable can be done in the
variable creation code path aswell.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/globalvar.c | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/common/globalvar.c b/common/globalvar.c
index 007e955..8f37c99 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -231,7 +231,7 @@ static int nv_param_set(struct device_d *dev, struct param_d *p, const char *val
static int __nvvar_add(const char *name, const char *value)
{
- struct param_d *p, *gp;
+ struct param_d *p;
int ret;
int devspace;
struct device_d *dev;
@@ -246,19 +246,12 @@ static int __nvvar_add(const char *name, const char *value)
devspace = ret;
- gp = get_param_by_name(&nv_device, name);
- if (gp) {
- if (!devspace) {
- ret = dev_set_param(&global_device, name, value);
- if (ret)
- return ret;
- }
-
- ret = dev_set_param(&nv_device, name, value);
- if (ret)
- return ret;
-
- return 0;
+ /* Get param. If it doesn't exist yet, create it */
+ p = get_param_by_name(&nv_device, name);
+ if (!p) {
+ p = dev_add_param(&nv_device, name, nv_param_set, nv_param_get, 0);
+ if (IS_ERR(p))
+ return PTR_ERR(p);
}
if (!devspace) {
@@ -267,10 +260,6 @@ static int __nvvar_add(const char *name, const char *value)
return ret;
}
- p = dev_add_param(&nv_device, name, nv_param_set, nv_param_get, 0);
- if (IS_ERR(p))
- return PTR_ERR(p);
-
if (!value) {
if (devspace) {
if (dev)
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 4/4] globalvar: Also create globalvars from for nonvolatile device vars
2016-09-22 8:11 [PATCH 1/4] globalvar: Allow to remove multiple globalvars using wildcards Sascha Hauer
2016-09-22 8:11 ` [PATCH 2/4] global: Make 'global' command behaviour consistent to 'nv' Sascha Hauer
2016-09-22 8:11 ` [PATCH 3/4] nv: simplify nvvar_add Sascha Hauer
@ 2016-09-22 8:11 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2016-09-22 8:11 UTC (permalink / raw)
To: Barebox List
nv variables beginning with "nv.dev.<devname>.<varname>" are directly
mirrored to <devname>.<varname> and there is no globalvar for it. To
make it a bit more consistent and to increase the visibility of the
nonvolatile device variables create globalvars for them aswell.
With this the propagation flow has changed from:
nv.dev.<devname>.<varname>
-> <devname>.<varname>
to:
nv.dev.<devname>.<varname>
-> global.dev.<devname>.<varname>
-> <devname>.<varname>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/globalvar.c | 75 ++++++++++++++++++++++--------------------------------
1 file changed, 30 insertions(+), 45 deletions(-)
diff --git a/common/globalvar.c b/common/globalvar.c
index 8f37c99..a2555cf 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -179,34 +179,14 @@ static int nvvar_device_dispatch(const char *name, struct device_d **dev,
static int nv_set(struct device_d *dev, struct param_d *p, const char *val)
{
int ret;
- int devspace;
- struct device_d *rdev;
- const char *pname;
if (!val)
val = "";
- ret = nvvar_device_dispatch(p->name, &rdev, &pname);
- if (ret < 0)
+ ret = dev_set_param(&global_device, p->name, val);
+ if (ret)
return ret;
- devspace = ret;
-
- if (devspace) {
- if (rdev) {
- ret = dev_set_param(rdev, pname, val);
- if (ret) {
- pr_err("Cannot init param from nv: %s.%s=%s: %s\n",
- dev_name(rdev), pname, val, strerror(-ret));
- return ret;
- }
- }
- } else {
- ret = dev_set_param(&global_device, p->name, val);
- if (ret)
- return ret;
- }
-
free(p->value);
p->value = xstrdup(val);
@@ -233,19 +213,10 @@ static int __nvvar_add(const char *name, const char *value)
{
struct param_d *p;
int ret;
- int devspace;
- struct device_d *dev;
- const char *pname;
if (!IS_ENABLED(CONFIG_NVVAR))
return -ENOSYS;
- ret = nvvar_device_dispatch(name, &dev, &pname);
- if (ret < 0)
- return ret;
-
- devspace = ret;
-
/* Get param. If it doesn't exist yet, create it */
p = get_param_by_name(&nv_device, name);
if (!p) {
@@ -254,20 +225,13 @@ static int __nvvar_add(const char *name, const char *value)
return PTR_ERR(p);
}
- if (!devspace) {
- ret = globalvar_add_simple(name, value);
- if (ret && ret != -EEXIST)
- return ret;
- }
+ /* Create corresponding globalvar if it doesn't exist yet */
+ ret = globalvar_add_simple(name, value);
+ if (ret && ret != -EEXIST)
+ return ret;
- if (!value) {
- if (devspace) {
- if (dev)
- value = dev_get_param(dev, pname);
- } else {
- value = dev_get_param(&global_device, name);
- }
- }
+ if (!value)
+ value = dev_get_param(&global_device, name);
return nv_set(&nv_device, p, value);
}
@@ -409,6 +373,27 @@ void globalvar_set_match(const char *match, const char *val)
}
}
+int globalvar_simple_set(struct device_d *dev, struct param_d *p, const char *val)
+{
+ struct device_d *rdev;
+ const char *pname;
+ int ret;
+
+ ret = nvvar_device_dispatch(p->name, &rdev, &pname);
+ if (ret < 0)
+ return ret;
+
+ if (ret && rdev) {
+ ret = dev_set_param(rdev, pname, val);
+ if (ret)
+ pr_err("Cannot init param from global: %s.%s=%s: %s\n",
+ dev_name(rdev), pname, val, strerror(-ret));
+ }
+
+ /* Pass to the generic function we have overwritten */
+ return dev_param_set_generic(dev, p, val);
+}
+
/*
* globalvar_add_simple
*
@@ -418,7 +403,7 @@ int globalvar_add_simple(const char *name, const char *value)
{
struct param_d *param;
- param = dev_add_param(&global_device, name, NULL, NULL,
+ param = dev_add_param(&global_device, name, globalvar_simple_set, NULL,
PARAM_GLOBALVAR_UNQUALIFIED);
if (IS_ERR(param)) {
if (PTR_ERR(param) != -EEXIST)
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread