mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/7 v2] globalvar: add multiple device support
@ 2013-03-13 18:01 Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
  2013-03-15  8:12 ` [PATCH 0/7 v2] globalvar: add multiple device support Sascha Hauer
  0 siblings, 2 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-13 18:01 UTC (permalink / raw)
  To: barebox

HI,

	v2:
	fix bootargs

	this will allow to reduce the scope of device and params to search
	during boot time

	we keep the retro compatibility

The following changes since commit 092bfd5eb55d1b2d7ed098aa9723a2fa63b86192:

  fix another brown paper bag bug introduced with compile time loglevel (2013-03-06 23:53:04 +0100)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git delivery/globalvar

for you to fetch changes up to 2a749c4b65f823da50537798a2feeaf4a01d2212:

  bootargs: switch globalvar to it's own device (2013-03-13 14:35:29 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (7):
      params: allow to access first sub-device and params via env
      globalvar: add it's own bus
      globalvar: allow to register multiple device
      net: switch to global device
      dhcp: switch globalvar to it's own device
      bootm: switch globalvar to it's own device
      bootargs: switch globalvar to it's own device

 commands/bootm.c    |   20 +++++++++++++-------
 commands/global.c   |   41 +++++++++++++++++++++++++++++++++--------
 common/bootargs.c   |   14 ++++++++++++--
 common/complete.c   |   45 ++++++++++++++++++++++++++++++++++++++++-----
 common/globalvar.c  |  150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
 include/globalvar.h |   26 ++++++++++++++++++++++++++
 lib/parameter.c     |   41 ++++++++++++++++++++++++++++++++++++++++-
 net/dhcp.c          |   40 ++++++++--------------------------------
 net/net.c           |   15 +++++++--------
 9 files changed, 311 insertions(+), 81 deletions(-)

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/7] params: allow to access first sub-device and params via env
  2013-03-13 18:01 [PATCH 0/7 v2] globalvar: add multiple device support Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-13 18:05 ` Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05   ` [PATCH 2/7] globalvar: add it's own bus Jean-Christophe PLAGNIOL-VILLARD
                     ` (5 more replies)
  2013-03-15  8:12 ` [PATCH 0/7 v2] globalvar: add multiple device support Sascha Hauer
  1 sibling, 6 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-13 18:05 UTC (permalink / raw)
  To: barebox

this will allow to keep retro-compatiblility and adding
globalvar multiple device support

 barebox@Somfy Animeo IP:/
 # echo $platform.soc.
 at91sam9260
 barebox@Somfy Animeo IP:/
 # echo $platform.soc.name
 Unknown
 barebox@Somfy Animeo IP:/
 # echo $global.dhcp.vendor_id
 barebox-animeo-ip

update complete too

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/complete.c |   45 ++++++++++++++++++++++++++++++++++++++++-----
 lib/parameter.c   |   41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 6 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index 9206ef0..17ee3c4 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -169,7 +169,7 @@ int device_complete(struct string_list *sl, char *instr)
 }
 EXPORT_SYMBOL(device_complete);
 
-static int device_param_complete(char *begin, struct device_d *dev,
+static int device_param_complete(char *begin, char *dev_fullname, struct device_d *dev,
 				 struct string_list *sl, char *instr)
 {
 	struct param_d *param;
@@ -185,7 +185,7 @@ static int device_param_complete(char *begin, struct device_d *dev,
 			continue;
 
 		string_list_add_asprintf(sl, "%s%s.%s%c",
-			begin ? begin : "", dev_name(dev), param->name,
+			begin ? begin : "", dev_fullname, param->name,
 			begin ? ' ' : '=');
 	}
 
@@ -253,12 +253,47 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
 	}
 
 	for_each_device(dev) {
-		if (!strncmp(instr, dev_name(dev), len)) {
+		struct device_d *child;
+		char *devname = asprintf("%s", dev_name(dev));
+
+		if (!strncmp(instr, devname, len)) {
 			if (eval)
-				device_param_complete("$", dev, sl, instr_param);
+				device_param_complete("$", devname, dev, sl, instr_param);
 			else
-				device_param_complete(NULL, dev, sl, instr_param);
+				device_param_complete(NULL, devname, dev, sl, instr_param);
+		}
+
+		if (dev->bus) {
+			free(devname);
+			continue;
+		}
+
+		device_for_each_child(dev, child) {
+			char *dev_fullname;
+			char *child_instr_param;
+			int child_len;
+
+			dev_fullname = asprintf("%s.%s", devname, dev_name(child));
+			child_instr_param = strchr(instr_param, '.');
+
+			if (child_instr_param) {
+				child_len = (child_instr_param - instr);
+				child_instr_param++;
+			} else {
+				child_len = strlen(instr);
+				child_instr_param = "";
+			}
+
+			if (!strncmp(instr, dev_fullname, child_len)) {
+				if (eval)
+					device_param_complete("$", dev_fullname, child, sl, child_instr_param);
+				else
+					device_param_complete(NULL, dev_fullname, child, sl, child_instr_param);
+			}
+
+			free(dev_fullname);
 		}
+		free(devname);
 	}
 
 	return 0;
diff --git a/lib/parameter.c b/lib/parameter.c
index c00b824..4b7b26a 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -28,7 +28,7 @@
 #include <malloc.h>
 #include <driver.h>
 
-struct param_d *get_param_by_name(struct device_d *dev, const char *name)
+static struct param_d *__get_param_by_name(struct device_d *dev, const char *name)
 {
 	struct param_d *p;
 
@@ -40,6 +40,45 @@ struct param_d *get_param_by_name(struct device_d *dev, const char *name)
 	return NULL;
 }
 
+static struct param_d *get_child_param_by_name(struct device_d *dev, const char *name)
+{
+	struct device_d *child;
+	char *devstr;
+	char *par;
+
+	if (dev->bus)
+		return NULL;
+
+	if (!strchr(name, '.'))
+		return NULL;
+
+	devstr = strdup(name);
+	par = strchr(devstr, '.');
+
+	*par = 0;
+	par++;
+
+	device_for_each_child(dev, child) {
+		if (!strcmp(devstr, dev_name(child)))
+			return __get_param_by_name(child, par);
+	}
+
+	free(devstr);
+
+	return NULL;
+}
+
+struct param_d *get_param_by_name(struct device_d *dev, const char *name)
+{
+	struct param_d *param;
+
+	param = get_child_param_by_name(dev, name);
+	if (param)
+		return param;
+
+	return __get_param_by_name(dev, name);
+}
+
 /**
  * dev_get_param - get the value of a parameter
  * @param dev	The device
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/7] globalvar: add it's own bus
  2013-03-13 18:05 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-13 18:05   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05   ` [PATCH 3/7] globalvar: allow to register multiple device Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-13 18:05 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/globalvar.c |   31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index a8aaa72..f275a38 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -3,17 +3,14 @@
 #include <globalvar.h>
 #include <init.h>
 
-static struct device_d global_device = {
-	.name = "global",
-	.id = DEVICE_ID_SINGLE,
-};
+static struct device_d *global_device;
 
 int globalvar_add(const char *name,
 		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
 		const char *(*get)(struct device_d *, struct param_d *p),
 		unsigned long flags)
 {
-	return dev_add_param(&global_device, name, set, get, flags);
+	return dev_add_param(global_device, name, set, get, flags);
 }
 
 /*
@@ -27,9 +24,9 @@ char *globalvar_get_match(const char *match, const char *seperator)
 	char *val = NULL;
 	struct param_d *param;
 
-	list_for_each_entry(param, &global_device.parameters, list) {
+	list_for_each_entry(param, global_device.parameters, list) {
 		if (!strncmp(match, param->name, strlen(match))) {
-			const char *p = dev_get_param(&global_device, param->name);
+			const char *p = dev_get_param(global_device, param->name);
 			if (val) {
 				char *new = asprintf("%s%s%s", val, seperator, p);
 				free(val);
@@ -50,9 +47,9 @@ void globalvar_set_match(const char *match, const char *val)
 {
 	struct param_d *param;
 
-	list_for_each_entry(param, &global_device.parameters, list) {
+	list_for_each_entry(param, global_device.parameters, list) {
 		if (!strncmp(match, param->name, strlen(match)))
-			dev_set_param(&global_device, param->name, val);
+			dev_set_param(global_device, param->name, val);
 	}
 }
 
@@ -66,10 +63,22 @@ int globalvar_add_simple(const char *name)
 	return globalvar_add(name, NULL, NULL, 0);
 }
 
+static int global_match(struct device_d *dev, struct driver_d *drv)
+{
+	return 1;
+}
+
+static struct bus_type global_bus = {
+	.name = "global",
+	.match = global_match,
+	.probe = dummy_probe,
+};
+
 static int globalvar_init(void)
 {
-	register_device(&global_device);
+	bus_register(&global_bus);
+	global_device = &global_bus->dev;
 
 	return 0;
 }
-postconsole_initcall(globalvar_init);
+pure_initcall(globalvar_init);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/7] globalvar: allow to register multiple device
  2013-03-13 18:05 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05   ` [PATCH 2/7] globalvar: add it's own bus Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-13 18:05   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05   ` [PATCH 4/7] net: switch to global device Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-13 18:05 UTC (permalink / raw)
  To: barebox

This will allow to reduce the time spend to search for globalvar
(boot time)

the access to the globalvar is retro-compatible

we can now create device via the global command

 barebox@Somfy Animeo IP:/
 # devinfo
 devices:
 `---- global
      `---- net
      `---- bootm
      `---- dhcp
      ...
 barebox@Somfy Animeo IP:/
 resources:
 driver: none
 bus: global
 bus: none

 Parameters:
         hostname =
 barebox@Somfy Animeo IP:/
 # devinfo net
 resources:
 driver: none
 bus: global

 Parameters:
       nameserver =
       domainname =
 barebox@Somfy Animeo IP:/
 # devinfo dhcp
 resources:
 driver: none
 bus: global

 Parameters:
         rootpath =
 tftp_server_name =
         bootfile =
      oftree_file =
        vendor_id = barebox-animeo-ip
        client_id =
       user_class =
      client_uuid =
 barebox@Somfy Animeo IP:/
 # devinfo bootm
 resources:
 driver: none
 bus: global

 Parameters:
            image =
           oftree =
           initrd =
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/global.c   |   41 ++++++++++++----
 common/globalvar.c  |  133 +++++++++++++++++++++++++++++++++++++++++++++------
 include/globalvar.h |   26 ++++++++++
 3 files changed, 178 insertions(+), 22 deletions(-)

diff --git a/commands/global.c b/commands/global.c
index 427a231..539fa21 100644
--- a/commands/global.c
+++ b/commands/global.c
@@ -23,14 +23,23 @@
 #include <environment.h>
 #include <getopt.h>
 
-static int globalvar_set(char* name, char* value)
+static int globalvar_set(char *devname, char* name, char* value)
 {
 	int ret;
 
-	ret = globalvar_add_simple(name);
+	if (devname) {
+		struct device_d *dev;
+
+		dev = get_device_by_name(devname);
+		if (!dev)
+			dev = global_add_device(devname);
+		ret = global_add_simple(dev, name);
+	} else {
+		ret = globalvar_add_simple(name);
+	}
 
 	if (value) {
-		char *tmp = asprintf("global.%s", name);
+		char *tmp = asprintf("%s.%s", devname ? devname : "global", name);
 		ret = setenv(tmp, value);
 		free(tmp);
 	}
@@ -43,12 +52,16 @@ static int do_global(int argc, char *argv[])
 	int opt;
 	int do_set_match = 0;
 	char *value;
+	char *devname = NULL;
 
-	while ((opt = getopt(argc, argv, "r")) > 0) {
+	while ((opt = getopt(argc, argv, "rd:")) > 0) {
 		switch (opt) {
 		case 'r':
 			do_set_match = 1;
 			break;
+		case 'd':
+			devname = optarg;
+			break;
 		}
 	}
 
@@ -68,17 +81,29 @@ static int do_global(int argc, char *argv[])
 		if (!value)
 			value = "";
 
-		globalvar_set_match(argv[0], value);
+		if (devname) {
+			struct device_d *dev;
+
+			dev = get_device_by_name(devname);
+
+			if (!dev)
+				return -EINVAL;
+
+			global_set_match(dev, argv[0], value);
+		} else {
+			globalvar_set_match(argv[0], value);
+		}
 		return 0;
 	}
 
-	return globalvar_set(argv[0], value);
+	return globalvar_set(devname, argv[0], value);
 }
 
 BAREBOX_CMD_HELP_START(global)
-BAREBOX_CMD_HELP_USAGE("global [-r] <var>[=<value]\n")
+BAREBOX_CMD_HELP_USAGE("global [-d device] [-r] <var>[=<value]\n")
 BAREBOX_CMD_HELP_SHORT("add a new global variable named <var>, optionally set to <value>\n")
-BAREBOX_CMD_HELP_SHORT("-r to set a value to of all globalvars beginning with 'match'")
+BAREBOX_CMD_HELP_SHORT("-r to set a value to of all globalvars beginning with 'match'\n")
+BAREBOX_CMD_HELP_SHORT("-d use a specific global device if do not exist create (if -r not set), it if not set use 'global'")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(global)
diff --git a/common/globalvar.c b/common/globalvar.c
index f275a38..5bfab70 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -14,19 +14,19 @@ int globalvar_add(const char *name,
 }
 
 /*
- * globalvar_get_match
+ * global_get_match
  *
- * get a concatenated string of all globalvars beginning with 'match'.
- * This adds whitespaces between the different globalvars
+ * get a concatenated string of all global vars beginning with 'match'.
+ * This adds whitespaces between the different global vars
  */
-char *globalvar_get_match(const char *match, const char *seperator)
+char *global_get_match(struct device_d *dev, const char *match, const char *seperator)
 {
 	char *val = NULL;
 	struct param_d *param;
 
-	list_for_each_entry(param, global_device.parameters, list) {
+	list_for_each_entry(param, &dev->parameters, list) {
 		if (!strncmp(match, param->name, strlen(match))) {
-			const char *p = dev_get_param(global_device, param->name);
+			const char *p = dev_get_param(dev, param->name);
 			if (val) {
 				char *new = asprintf("%s%s%s", val, seperator, p);
 				free(val);
@@ -43,14 +43,75 @@ char *globalvar_get_match(const char *match, const char *seperator)
 	return val;
 }
 
-void globalvar_set_match(const char *match, const char *val)
+/*
+ * globalvar_get_match
+ *
+ * get a concatenated string of all globalvars beginning with 'match'.
+ * This adds whitespaces between the different globalvars
+ */
+char *globalvar_get_match(const char *match, const char *seperator)
+{
+	return global_get_match(global_device, match, seperator);
+}
+
+void global_set_match(struct device_d *dev, const char *match, const char *val)
 {
 	struct param_d *param;
 
-	list_for_each_entry(param, global_device.parameters, list) {
+	list_for_each_entry(param, &dev->parameters, list) {
 		if (!strncmp(match, param->name, strlen(match)))
-			dev_set_param(global_device, param->name, val);
+			dev_set_param(dev, param->name, val);
+	}
+}
+
+void globalvar_set_match(const char *match, const char *val)
+{
+	struct device_d *child;
+	char *tmp = NULL;
+	char *submatch = "";
+
+	if (strchr(match, '.')) {
+		tmp = strdup(match);
+		submatch = strchr(tmp, '.');
+		*submatch = 0;
+		submatch++;
+	}
+
+	global_set_match(global_device, match, val);
+
+	device_for_each_child(global_device, child) {
+		const char *devname = dev_name(child);
+
+		if (tmp && !strcmp(devname, tmp))
+			global_set_match(child, submatch, val);
+
+		if (!strncmp(devname, match, strlen(match)))
+			global_set_match(child, "", val);
+	}
+
+	free(tmp);
+}
+
+/*
+ * global_add_simple
+ *
+ * add a new global named 'name'
+ */
+int global_add_simple(struct device_d *dev, const char *name)
+{
+	return dev_add_param(dev, name, NULL, NULL, 0);
+}
+
+static struct device_d *global_get_child_by_name(const char *name)
+{
+	struct device_d *child;
+
+	device_for_each_child(global_device, child) {
+		if (!strcmp(dev_name(child), name))
+			return child;
 	}
+
+	return NULL;
 }
 
 /*
@@ -60,7 +121,31 @@ void globalvar_set_match(const char *match, const char *val)
  */
 int globalvar_add_simple(const char *name)
 {
-	return globalvar_add(name, NULL, NULL, 0);
+	struct device_d *dev = global_device;
+	const char *subname = name;
+	char *tmp = NULL;
+	int ret;
+
+	if (strchr(name, '.')) {
+		char *data;
+
+		tmp = strdup(name);
+		data = strchr(tmp, '.');
+		*data = 0;
+		subname = ++data;
+
+		dev = global_get_child_by_name(tmp);
+		if (!dev) {
+			dev = global_device;
+			subname = name;
+		}
+	}
+
+	ret = global_add_simple(dev, subname);
+
+	free(tmp);
+
+	return ret;
 }
 
 static int global_match(struct device_d *dev, struct driver_d *drv)
@@ -74,11 +159,31 @@ static struct bus_type global_bus = {
 	.probe = dummy_probe,
 };
 
-static int globalvar_init(void)
+struct device_d *global_add_device(const char *name)
+{
+	struct device_d *dev;
+
+	dev = xzalloc(sizeof(struct device_d));
+
+	strcpy(dev->name, name);
+	dev->id = DEVICE_ID_SINGLE;
+	dev->bus = &global_bus;
+
+	register_device(dev);
+
+	return dev;
+}
+
+static int global_bus_init(void)
 {
-	bus_register(&global_bus);
-	global_device = &global_bus->dev;
+	int ret;
+
+	ret = bus_register(&global_bus);
+	if (ret)
+		return ret;
+
+	global_device = &global_bus.dev;
 
 	return 0;
 }
-pure_initcall(globalvar_init);
+pure_initcall(global_bus_init);
diff --git a/include/globalvar.h b/include/globalvar.h
index ddf885f..322a1cb 100644
--- a/include/globalvar.h
+++ b/include/globalvar.h
@@ -2,6 +2,7 @@
 #define __GLOBALVAR_H
 
 #ifdef CONFIG_GLOBALVAR
+struct device_d *global_add_device(const char *name);
 int globalvar_add_simple(const char *name);
 
 int globalvar_add(const char *name,
@@ -10,6 +11,13 @@ int globalvar_add(const char *name,
 		unsigned long flags);
 char *globalvar_get_match(const char *match, const char *seperator);
 void globalvar_set_match(const char *match, const char *val);
+
+struct device_d *global_add_device(const char *name);
+int global_add_simple(struct device_d *dev, const char *name);
+void global_set_match(struct device_d *dev, const char *match,
+			const char *val);
+char *global_get_match(struct device_d *dev, const char *match,
+			const char *seperator);
 #else
 static inline int globalvar_add_simple(const char *name)
 {
@@ -30,6 +38,24 @@ static inline char *globalvar_get_match(const char *match, const char *seperator
 }
 
 static inline void globalvar_set_match(const char *match, const char *val) {}
+
+static inline struct device_d *global_add_device(const char *name)
+{
+	return NULL;
+}
+
+static inline int global_add_simple(struct device_d *dev, const char *name)
+{
+	return 0;
+}
+
+static inline void global_set_match(struct device_d *dev, const char *match,
+			const char *val) {}
+static inline char *global_get_match(struct device_d *dev, const char *match,
+			const char *seperator)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __GLOBALVAR_H */
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/7] net: switch to global device
  2013-03-13 18:05 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05   ` [PATCH 2/7] globalvar: add it's own bus Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05   ` [PATCH 3/7] globalvar: allow to register multiple device Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-13 18:05   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05   ` [PATCH 5/7] dhcp: switch globalvar to it's own device Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-13 18:05 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 net/net.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/net/net.c b/net/net.c
index 639bc2d..4888d60 100644
--- a/net/net.c
+++ b/net/net.c
@@ -35,6 +35,7 @@
 #include <init.h>
 #include <linux/ctype.h>
 #include <linux/err.h>
+#include <globalvar.h>
 
 static IPaddr_t	net_netmask;		/* Our subnet mask (0=unknown)	*/
 static IPaddr_t	net_gateway;		/* Our gateways IP address	*/
@@ -664,21 +665,19 @@ out:
 	return ret;
 }
 
-static struct device_d net_device = {
-	.name = "net",
-	.id = DEVICE_ID_SINGLE,
-};
-
 static int net_init(void)
 {
+	struct device_d *dev;
 	int i;
 
 	for (i = 0; i < PKTBUFSRX; i++)
 		NetRxPackets[i] = net_alloc_packet();
 
-	register_device(&net_device);
-	dev_add_param(&net_device, "nameserver", NULL, NULL, 0);
-	dev_add_param(&net_device, "domainname", NULL, NULL, 0);
+	dev = global_add_device("net");
+	if (dev) {
+		global_add_simple(dev, "nameserver");
+		global_add_simple(dev, "domainname");
+	}
 
 	return 0;
 }
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/7] dhcp: switch globalvar to it's own device
  2013-03-13 18:05 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 preceding siblings ...)
  2013-03-13 18:05   ` [PATCH 4/7] net: switch to global device Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-13 18:05   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05   ` [PATCH 6/7] bootm: " Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05   ` [PATCH 7/7] bootargs: " Jean-Christophe PLAGNIOL-VILLARD
  5 siblings, 0 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-13 18:05 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 net/dhcp.c |   40 ++++++++--------------------------------
 1 file changed, 8 insertions(+), 32 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index 8233ec3..7fde0d8 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -81,31 +81,16 @@ static uint32_t dhcp_leasetime;
 static IPaddr_t net_dhcp_server_ip;
 static uint64_t dhcp_start;
 static char dhcp_tftpname[256];
+static struct device_d *dhcp_dev;
 
 static const char* dhcp_get_barebox_global(const char * var)
 {
-	char * var_global = asprintf("global.dhcp.%s", var);
-	const char *val;
-
-	if (!var_global)
-		return NULL;
-
-	val = getenv(var_global);
-	free(var_global);
-	return val;
+	return dev_get_param(dhcp_dev, var);
 }
 
 static int dhcp_set_barebox_global(const char * var, char *val)
 {
-	char * var_global = asprintf("global.dhcp.%s", var);
-	int ret;
-
-	if (!var_global)
-		return -ENOMEM;
-
-	ret = setenv(var_global, val);
-	free(var_global);
-	return ret;
+	return dev_set_param(dhcp_dev, var, val);
 }
 
 struct dhcp_opt {
@@ -663,30 +648,21 @@ static void dhcp_reset_env(void)
 	}
 }
 
-static void dhcp_global_add(const char *var)
-{
-	char * var_global = asprintf("dhcp.%s", var);
-
-	if (!var_global)
-		return;
-
-	globalvar_add_simple(var_global);
-	free(var_global);
-}
-
 static int dhcp_global_init(void)
 {
 	struct dhcp_opt *opt;
 	struct dhcp_param *param;
 	int i;
 
+	dhcp_dev = global_add_device("dhcp");
+
 	for (i = 0; i < ARRAY_SIZE(dhcp_options); i++) {
 		opt = &dhcp_options[i];
 
 		if (!opt->barebox_dhcp_global)
 			continue;
 
-		dhcp_global_add(opt->barebox_dhcp_global);
+		global_add_simple(dhcp_dev, opt->barebox_dhcp_global);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(dhcp_params); i++) {
@@ -695,7 +671,7 @@ static int dhcp_global_init(void)
 		if (!param->barebox_dhcp_global)
 			continue;
 
-		dhcp_global_add(param->barebox_dhcp_global);
+		global_add_simple(dhcp_dev, param->barebox_dhcp_global);
 	}
 
 	return 0;
@@ -719,7 +695,7 @@ static int do_dhcp(int argc, char *argv[])
 
 	dhcp_reset_env();
 
-	dhcp_getenv_int("global.dhcp.retries", &retries);
+	dhcp_getenv_int("dhcp.retries", &retries);
 
 	while((opt = getopt(argc, argv, "H:v:c:u:U:r:")) > 0) {
 		switch(opt) {
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/7] bootm: switch globalvar to it's own device
  2013-03-13 18:05 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 preceding siblings ...)
  2013-03-13 18:05   ` [PATCH 5/7] dhcp: switch globalvar to it's own device Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-13 18:05   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05   ` [PATCH 7/7] bootargs: " Jean-Christophe PLAGNIOL-VILLARD
  5 siblings, 0 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-13 18:05 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/bootm.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 4d3f022..b70cd05 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -48,6 +48,12 @@
 #include <asm-generic/memory_layout.h>
 
 static LIST_HEAD(handler_list);
+static struct device_d *bootm_dev;
+
+static const char* bootm_get_global(const char * var)
+{
+	return dev_get_param(bootm_dev, var);
+}
 
 /*
  * Additional oftree size for the fixed tree
@@ -265,10 +271,10 @@ static int do_bootm(int argc, char *argv[])
 	data.verify = 0;
 	data.verbose = 0;
 
-	oftree = getenv("global.bootm.oftree");
-	os_file = getenv("global.bootm.image");
+	oftree = bootm_get_global("oftree");
+	os_file = bootm_get_global("image");
 	if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD))
-		initrd_file = getenv("global.bootm.initrd");
+		initrd_file = bootm_get_global("initrd");
 
 	while ((opt = getopt(argc, argv, BOOTM_OPTS)) > 0) {
 		switch(opt) {
@@ -443,11 +449,11 @@ err_out:
 
 static int bootm_init(void)
 {
-
-	globalvar_add_simple("bootm.image");
-	globalvar_add_simple("bootm.oftree");
+	bootm_dev = global_add_device("bootm");
+	global_add_simple(bootm_dev, "image");
+	global_add_simple(bootm_dev, "oftree");
 	if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD))
-		globalvar_add_simple("bootm.initrd");
+		global_add_simple(bootm_dev, "initrd");
 
 	return 0;
 }
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/7] bootargs: switch globalvar to it's own device
  2013-03-13 18:05 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 preceding siblings ...)
  2013-03-13 18:05   ` [PATCH 6/7] bootm: " Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-13 18:05   ` Jean-Christophe PLAGNIOL-VILLARD
  5 siblings, 0 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-13 18:05 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/bootargs.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/common/bootargs.c b/common/bootargs.c
index 6624f72..e9248ab 100644
--- a/common/bootargs.c
+++ b/common/bootargs.c
@@ -22,9 +22,11 @@
 #include <magicvar.h>
 #include <globalvar.h>
 #include <environment.h>
+#include <init.h>
 
 static char *linux_bootargs;
 static int linux_bootargs_overwritten;
+static struct device_d *global_linux_dev;
 
 /*
  * This returns the Linux bootargs
@@ -45,11 +47,11 @@ const char *linux_bootargs_get(void)
 
 	free(linux_bootargs);
 
-	bootargs = globalvar_get_match("linux.bootargs.", " ");
+	bootargs = global_get_match(global_linux_dev, "bootargs.", " ");
 	if (!strlen(bootargs))
 		return getenv("bootargs");
 
-	mtdparts = globalvar_get_match("linux.mtdparts.", ";");
+	mtdparts = global_get_match(global_linux_dev, "mtdparts.", ";");
 
 	if (strlen(mtdparts)) {
 		linux_bootargs = asprintf("%s mtdparts=%s", bootargs, mtdparts);
@@ -76,5 +78,13 @@ int linux_bootargs_overwrite(const char *bootargs)
 	return 0;
 }
 
+static int bootargs_init(void)
+{
+	global_linux_dev = global_add_device("linux");
+
+	return 0;
+}
+late_initcall(bootargs_init);
+
 BAREBOX_MAGICVAR_NAMED(global_linux_bootargs_, global.linux.bootargs.*, "Linux bootargs variables");
 BAREBOX_MAGICVAR_NAMED(global_linux_mtdparts_, global.linux.mtdparts.*, "Linux mtdparts variables");
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/7 v2] globalvar: add multiple device support
  2013-03-13 18:01 [PATCH 0/7 v2] globalvar: add multiple device support Jean-Christophe PLAGNIOL-VILLARD
  2013-03-13 18:05 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-15  8:12 ` Sascha Hauer
  1 sibling, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2013-03-15  8:12 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Wed, Mar 13, 2013 at 07:01:00PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> HI,
> 
> 	v2:
> 	fix bootargs
> 
> 	this will allow to reduce the scope of device and params to search
> 	during boot time
> 
> 	we keep the retro compatibility
> 
> The following changes since commit 092bfd5eb55d1b2d7ed098aa9723a2fa63b86192:
> 
>   fix another brown paper bag bug introduced with compile time loglevel (2013-03-06 23:53:04 +0100)
> 
> are available in the git repository at:
> 
>   git://git.jcrosoft.org/barebox.git delivery/globalvar
> 
> for you to fetch changes up to 2a749c4b65f823da50537798a2feeaf4a01d2212:
> 
>   bootargs: switch globalvar to it's own device (2013-03-13 14:35:29 +0800)

I still don't see why we should take this. You say it's about speed.
I made some measurments. I read some global variables 1000 times each,
below times are in ms:

Vanilla -next tree:
-------------------------------------
global.linux.mtdparts.nand0:	49178
global.dhcp.rootpath:		45282
dhcp.rootpath:			90329
global.sumsen:			47681

-next with your patches:
-------------------------------------
global.linux.mtdparts.nand0:	11407
global.dhcp.rootpath:		13961
dhcp.rootpath:			92394
global.sumsen:			 5087

-next with register_device(&global_device) moved to pure_initcall:
-------------------------------------
global.linux.mtdparts.nand0:	 8467
global.dhcp.rootpath:		 5162
dhcp.rootpath:			90096
global.sumsen:			 6541

(Moving registration of the global device simply has the effect that
it is in the beginning of the devices list, thus we can find it faster)

So your patches indeed make reading the global variables significantly
faster, but a simple one-liner patch shows makes it even faster.

So, no. We don't introduce new APIs just for the sake of it.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-03-15  8:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-13 18:01 [PATCH 0/7 v2] globalvar: add multiple device support Jean-Christophe PLAGNIOL-VILLARD
2013-03-13 18:05 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
2013-03-13 18:05   ` [PATCH 2/7] globalvar: add it's own bus Jean-Christophe PLAGNIOL-VILLARD
2013-03-13 18:05   ` [PATCH 3/7] globalvar: allow to register multiple device Jean-Christophe PLAGNIOL-VILLARD
2013-03-13 18:05   ` [PATCH 4/7] net: switch to global device Jean-Christophe PLAGNIOL-VILLARD
2013-03-13 18:05   ` [PATCH 5/7] dhcp: switch globalvar to it's own device Jean-Christophe PLAGNIOL-VILLARD
2013-03-13 18:05   ` [PATCH 6/7] bootm: " Jean-Christophe PLAGNIOL-VILLARD
2013-03-13 18:05   ` [PATCH 7/7] bootargs: " Jean-Christophe PLAGNIOL-VILLARD
2013-03-15  8:12 ` [PATCH 0/7 v2] globalvar: add multiple device support Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox