Skip to contentSkip to conversation

globalvar: add multiple device support

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 3 participants 12 messages Jan 25, 2013 – Jan 27, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover globalvar: add multiple device support

HI,

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 2c93912f34ce06585c4ede0298aef7225e096df2:

atmel_mci: gpio: request and configure card detect (2013-01-25 19:52:44 +0100)

are available in the git repository at:

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

for you to fetch changes up to 1ea180426705fda69e278057337d6e00240fd270:

bootargs: switch globalvar to it's own device (2013-01-22 02:30:00 +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  |  146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
 include/globalvar.h |   26 ++++++++++++++++++++++++
 lib/parameter.c     |   41 +++++++++++++++++++++++++++++++++++++-
 net/dhcp.c          |   40 ++++++++-----------------------------
 net/net.c           |   15 +++++++-------
 9 files changed, 307 insertions(+), 81 deletions(-)

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/7 params: allow to access first sub-device and params via env

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

---
 common/complete.c |   45 ++++++++++++++++++++++++++++++++++++++++-----
 lib/parameter.c   |   41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 6 deletions(-)
common/complete.c +40 -5
index 9206ef0..17ee3c4 100644
@@ -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;
lib/parameter.c +40 -1

53 lines not on this page · raw message

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/7 globalvar: add it's own bus

---
 common/globalvar.c |   31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
common/globalvar.c +20 -11
index a8aaa72..f275a38 100644
@@ -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);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 3/7 globalvar: allow to register multiple device

In reply to Jean-Christophe PLAGNIOL-VILLARD

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 =

---
 commands/global.c   |   41 ++++++++++++----
 common/globalvar.c  |  129 +++++++++++++++++++++++++++++++++++++++++++++------
 include/globalvar.h |   26 +++++++++++
 3 files changed, 174 insertions(+), 22 deletions(-)
commands/global.c +33 -8
index 427a231..539fa21 100644
@@ -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)
common/globalvar.c +115 -14

166 lines not on this page · raw message

include/globalvar.h +26 -0
index ddf885f..c1d73c4 100644
@@ -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) {}
+
+struct device_d *global_add_device(const char *name)
+{
+	return NULL;
+}
+
+int global_add_simple(struct device_d *dev, const char *name)
+{
+	return 0;
+}
+
+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)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __GLOBALVAR_H */
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH 4/7 net: switch to global device

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 net/net.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
net/net.c +7 -8
index 639bc2d..4888d60 100644
@@ -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;
 }
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH 5/7 dhcp: switch globalvar to it's own device

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 net/dhcp.c |   40 ++++++++--------------------------------
 1 file changed, 8 insertions(+), 32 deletions(-)
net/dhcp.c +8 -32
index 768255e..486b407 100644
@@ -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) {
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH 6/7 bootm: switch globalvar to it's own device

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 commands/bootm.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
commands/bootm.c +13 -7
index 483e6a1..830def4 100644
@@ -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
@@ -286,10 +292,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) {
@@ -459,11 +465,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;
 }
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH 7/7 bootargs: switch globalvar to it's own device

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 common/bootargs.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
common/bootargs.c +12 -2
index 6624f72..d82d853 100644
@@ -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 char *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");
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

Re: [PATCH 1/7] params: allow to access first sub-device and params via env

In reply to Jean-Christophe PLAGNIOL-VILLARD

Hi,

Quoted 122 lines · Jean-Christophe PLAGNIOL-VILLARD

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

---
 common/complete.c |   45 ++++++++++++++++++++++++++++++++++++++++-----
 lib/parameter.c   |   41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 6 deletions(-)
common/complete.c +40 -5
index 9206ef0..17ee3c4 100644
@@ -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;
lib/parameter.c +12 -1
index c00b824..4b7b26a 100644
@@ -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;

lib/parameter.c struct param_d *get_param_by_name(struct device_d *dev, const char *name) · line 63

Quoted 10 lines
lib/parameter.c +10 -0
+
+	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);

Need to call 'free(devstr)' before return?

Quoted 29 lines
lib/parameter.c +18 -0
+	}
+
+	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
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#9 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 7 lines · Jean-Christophe PLAGNIOL-VILLARD

HI,

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

we keep the retro compatibility

Quoted 7 lines

The following changes since commit 2c93912f34ce06585c4ede0298aef7225e096df2:

atmel_mci: gpio: request and configure card detect (2013-01-25 19:52:44 +0100)

are available in the git repository at:

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

When compiling this I get:

common/bootargs.c: In function 'linux_bootargs_get':
common/bootargs.c:50:2: warning: passing argument 1 of 'global_get_match' from incompatible pointer type [enabled by default] In file included from common/bootargs.c:23:0:
include/globalvar.h:19:7: note: expected 'struct device_d *' but argument is of type 'char *' common/bootargs.c:54:2: warning: passing argument 1 of 'global_get_match' from incompatible pointer type [enabled by default] In file included from common/bootargs.c:23:0:
include/globalvar.h:19:7: note: expected 'struct device_d *' but argument is of type 'char *' common/bootargs.c: In function 'bootargs_init':
common/bootargs.c:83:19: warning: assignment from incompatible pointer type [enabled by default]

When starting this I get:

unable to handle NULL pointer dereference at address 0x00000068

pc : [<a7f1f928>]    lr : [<a7f1faf8>]

sp : a6effc18 ip : 00000002 fp : 00000000
r10: a6ffdf2c r9 : a6ffd704 r8 : a6ffb009
r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000
r3 : 00000000 r2 : 00000000 r1 : a6ffb009 r0 : 00000000
Flags: nZCv IRQs off FIQs off Mode SVC_32
[<a7f1f928>] (get_param_by_name+0xc/0xb4) from [<a7f1faf8>] (dev_add_param+0x18/0x94) [<a7f1faf8>] (dev_add_param+0x18/0x94) from [<a7f07800>] (global_add_simple+0x14/0x18) [<a7f07800>] (global_add_simple+0x14/0x18) from [<a7f0789c>] (globalvar_add_simple+0x98/0xb0) [<a7f0789c>] (globalvar_add_simple+0x98/0xb0) from [<a7f1e438>] (do_global+0x110/0x188) [<a7f1e438>] (do_global+0x110/0x188) from [<a7f05940>] (execute_command+0x38/0x78) [<a7f05940>] (execute_command+0x38/0x78) from [<a7f02150>] (run_list_real+0x7e0/0x938) [<a7f02150>] (run_list_real+0x7e0/0x938) from [<a7f01798>] (parse_stream_outer+0x198/0x270) [<a7f01798>] (parse_stream_outer+0x198/0x270) from [<a7f0190c>] (parse_string_outer+0x9c/0x100) [<a7f0190c>] (parse_string_outer+0x9c/0x100) from [<a7f022e8>] (source_script+0x40/0x78)
...

Overall I'm not sure this is worth it. I did some measurements on a 400MHz ARM9 board. From startup until booting the kernel barebox spends about 5.5ms in getenv/setenv. This can be reduced quite easily to 3ms by moving globalvar_init to a core_initcall.

Anyway, the series is not mergable as is. Also the search through subdevices of the globalvar device seems to have some undesirable side effects.

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw
Quoted 48 lines · Sascha Hauer
Quoted 7 lines · Jean-Christophe PLAGNIOL-VILLARD

HI,

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

we keep the retro compatibility

Quoted 7 lines

The following changes since commit 2c93912f34ce06585c4ede0298aef7225e096df2:

atmel_mci: gpio: request and configure card detect (2013-01-25 19:52:44 +0100)

are available in the git repository at:

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

When compiling this I get:

common/bootargs.c: In function 'linux_bootargs_get':
common/bootargs.c:50:2: warning: passing argument 1 of 'global_get_match' from incompatible pointer type [enabled by default] In file included from common/bootargs.c:23:0:
include/globalvar.h:19:7: note: expected 'struct device_d *' but argument is of type 'char *' common/bootargs.c:54:2: warning: passing argument 1 of 'global_get_match' from incompatible pointer type [enabled by default] In file included from common/bootargs.c:23:0:
include/globalvar.h:19:7: note: expected 'struct device_d *' but argument is of type 'char *' common/bootargs.c: In function 'bootargs_init':
common/bootargs.c:83:19: warning: assignment from incompatible pointer type [enabled by default]

When starting this I get:

unable to handle NULL pointer dereference at address 0x00000068

pc : [<a7f1f928>]    lr : [<a7f1faf8>]

sp : a6effc18 ip : 00000002 fp : 00000000
r10: a6ffdf2c r9 : a6ffd704 r8 : a6ffb009
r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000
r3 : 00000000 r2 : 00000000 r1 : a6ffb009 r0 : 00000000
Flags: nZCv IRQs off FIQs off Mode SVC_32
[<a7f1f928>] (get_param_by_name+0xc/0xb4) from [<a7f1faf8>] (dev_add_param+0x18/0x94) [<a7f1faf8>] (dev_add_param+0x18/0x94) from [<a7f07800>] (global_add_simple+0x14/0x18) [<a7f07800>] (global_add_simple+0x14/0x18) from [<a7f0789c>] (globalvar_add_simple+0x98/0xb0) [<a7f0789c>] (globalvar_add_simple+0x98/0xb0) from [<a7f1e438>] (do_global+0x110/0x188) [<a7f1e438>] (do_global+0x110/0x188) from [<a7f05940>] (execute_command+0x38/0x78) [<a7f05940>] (execute_command+0x38/0x78) from [<a7f02150>] (run_list_real+0x7e0/0x938) [<a7f02150>] (run_list_real+0x7e0/0x938) from [<a7f01798>] (parse_stream_outer+0x198/0x270) [<a7f01798>] (parse_stream_outer+0x198/0x270) from [<a7f0190c>] (parse_string_outer+0x9c/0x100) [<a7f0190c>] (parse_string_outer+0x9c/0x100) from [<a7f022e8>] (source_script+0x40/0x78)
...

Quoted 7 lines

Overall I'm not sure this is worth it. I did some measurements on a 400MHz ARM9 board. From startup until booting the kernel barebox spends about 5.5ms in getenv/setenv. This can be reduced quite easily to 3ms by moving globalvar_init to a core_initcall.

Anyway, the series is not mergable as is. Also the search through subdevices of the globalvar device seems to have some undesirable side effects.

I test here no issue wired

I test also here with more global ar about 100

I found 200ms diff on the all boot (cold start)

which for my case is critical

which config do you use?

Best Regards,
J.

Quoted 10 lines

Sascha

Signature · 4 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#11 lore raw
Quoted 59 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 48 lines · Sascha Hauer
Quoted 7 lines · Jean-Christophe PLAGNIOL-VILLARD

HI,

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

we keep the retro compatibility

Quoted 7 lines

The following changes since commit 2c93912f34ce06585c4ede0298aef7225e096df2:

atmel_mci: gpio: request and configure card detect (2013-01-25 19:52:44 +0100)

are available in the git repository at:

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

When compiling this I get:

common/bootargs.c: In function 'linux_bootargs_get':
common/bootargs.c:50:2: warning: passing argument 1 of 'global_get_match' from incompatible pointer type [enabled by default] In file included from common/bootargs.c:23:0:
include/globalvar.h:19:7: note: expected 'struct device_d *' but argument is of type 'char *' common/bootargs.c:54:2: warning: passing argument 1 of 'global_get_match' from incompatible pointer type [enabled by default] In file included from common/bootargs.c:23:0:
include/globalvar.h:19:7: note: expected 'struct device_d *' but argument is of type 'char *' common/bootargs.c: In function 'bootargs_init':
common/bootargs.c:83:19: warning: assignment from incompatible pointer type [enabled by default]

When starting this I get:

unable to handle NULL pointer dereference at address 0x00000068

pc : [<a7f1f928>]    lr : [<a7f1faf8>]

sp : a6effc18 ip : 00000002 fp : 00000000
r10: a6ffdf2c r9 : a6ffd704 r8 : a6ffb009
r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000
r3 : 00000000 r2 : 00000000 r1 : a6ffb009 r0 : 00000000
Flags: nZCv IRQs off FIQs off Mode SVC_32
[<a7f1f928>] (get_param_by_name+0xc/0xb4) from [<a7f1faf8>] (dev_add_param+0x18/0x94) [<a7f1faf8>] (dev_add_param+0x18/0x94) from [<a7f07800>] (global_add_simple+0x14/0x18) [<a7f07800>] (global_add_simple+0x14/0x18) from [<a7f0789c>] (globalvar_add_simple+0x98/0xb0) [<a7f0789c>] (globalvar_add_simple+0x98/0xb0) from [<a7f1e438>] (do_global+0x110/0x188) [<a7f1e438>] (do_global+0x110/0x188) from [<a7f05940>] (execute_command+0x38/0x78) [<a7f05940>] (execute_command+0x38/0x78) from [<a7f02150>] (run_list_real+0x7e0/0x938) [<a7f02150>] (run_list_real+0x7e0/0x938) from [<a7f01798>] (parse_stream_outer+0x198/0x270) [<a7f01798>] (parse_stream_outer+0x198/0x270) from [<a7f0190c>] (parse_string_outer+0x9c/0x100) [<a7f0190c>] (parse_string_outer+0x9c/0x100) from [<a7f022e8>] (source_script+0x40/0x78)
...

Quoted 7 lines

Overall I'm not sure this is worth it. I did some measurements on a 400MHz ARM9 board. From startup until booting the kernel barebox spends about 5.5ms in getenv/setenv. This can be reduced quite easily to 3ms by moving globalvar_init to a core_initcall.

Anyway, the series is not mergable as is. Also the search through subdevices of the globalvar device seems to have some undesirable side effects.

I test here no issue wired

Quoted 7 lines

I test also here with more global ar about 100

I found 200ms diff on the all boot (cold start)

which for my case is critical

which config do you use?

pcm038_defconfig

See the attached patch

commit 3bbc0037970e35dab9838980bbd5dfb67cf2dada

Author: Sascha Hauer <[email protected]>
Date:   Sun Jan 27 00:53:14 2013 +0100

fix

common/bootargs.c +1 -1
index d82d853..e9248ab 100644
@@ -26,7 +26,7 @@
 
 static char *linux_bootargs;
 static int linux_bootargs_overwritten;
-static char *global_linux_dev;
+static struct device_d *global_linux_dev;
 
 /*
  * This returns the Linux bootargs
common/globalvar.c +5 -0
index d0aa2a3..aa4f8a0 100644
@@ -135,6 +135,11 @@ int globalvar_add_simple(const char *name)
 		subname = ++data;
 
 		dev = global_get_child_by_name(tmp);
+		if (!dev) {
+			dev = global_device;
+			subname = name;
+		}
+
 	}
 
 	ret = global_add_simple(dev, subname);
Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox