* [PATCH 0/7] globalvar: add multiple device support @ 2013-01-25 23:53 Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD 2013-01-27 10:08 ` [PATCH 0/7] globalvar: add multiple device support Sascha Hauer 0 siblings, 2 replies; 13+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:53 UTC (permalink / raw) To: barebox 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 barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/7] params: allow to access first sub-device and params via env 2013-01-25 23:53 [PATCH 0/7] globalvar: add multiple device support Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 ` Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 2/7] globalvar: add it's own bus Jean-Christophe PLAGNIOL-VILLARD ` (6 more replies) 2013-01-27 10:08 ` [PATCH 0/7] globalvar: add multiple device support Sascha Hauer 1 sibling, 7 replies; 13+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 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] 13+ messages in thread
* [PATCH 2/7] globalvar: add it's own bus 2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 ` Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 3/7] globalvar: allow to register multiple device Jean-Christophe PLAGNIOL-VILLARD ` (5 subsequent siblings) 6 siblings, 0 replies; 13+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 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] 13+ messages in thread
* [PATCH 3/7] globalvar: allow to register multiple device 2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 2/7] globalvar: add it's own bus Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 ` Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 4/7] net: switch to global device Jean-Christophe PLAGNIOL-VILLARD ` (4 subsequent siblings) 6 siblings, 0 replies; 13+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 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 | 129 +++++++++++++++++++++++++++++++++++++++++++++------ include/globalvar.h | 26 +++++++++++ 3 files changed, 174 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..d0aa2a3 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,27 @@ 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); + } + + ret = global_add_simple(dev, subname); + + free(tmp); + + return ret; } static int global_match(struct device_d *dev, struct driver_d *drv) @@ -74,11 +155,31 @@ static struct bus_type global_bus = { .probe = dummy_probe, }; -static int globalvar_init(void) +struct device_d *global_add_device(const char *name) { - bus_register(&global_bus); - global_device = &global_bus->dev; + 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) +{ + 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..c1d73c4 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) {} + +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 */ -- 1.7.10.4 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 4/7] net: switch to global device 2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 2/7] globalvar: add it's own bus Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 3/7] globalvar: allow to register multiple device Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 ` Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 5/7] dhcp: switch globalvar to it's own device Jean-Christophe PLAGNIOL-VILLARD ` (3 subsequent siblings) 6 siblings, 0 replies; 13+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 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] 13+ messages in thread
* [PATCH 5/7] dhcp: switch globalvar to it's own device 2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD ` (2 preceding siblings ...) 2013-01-25 23:55 ` [PATCH 4/7] net: switch to global device Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 ` Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 6/7] bootm: " Jean-Christophe PLAGNIOL-VILLARD ` (2 subsequent siblings) 6 siblings, 0 replies; 13+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 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 768255e..486b407 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] 13+ messages in thread
* [PATCH 6/7] bootm: switch globalvar to it's own device 2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD ` (3 preceding siblings ...) 2013-01-25 23:55 ` [PATCH 5/7] dhcp: switch globalvar to it's own device Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 ` Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 7/7] bootargs: " Jean-Christophe PLAGNIOL-VILLARD 2013-01-26 0:45 ` [PATCH 1/7] params: allow to access first sub-device and params via env Alexander Aring 6 siblings, 0 replies; 13+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 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 483e6a1..830def4 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 @@ -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; } -- 1.7.10.4 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 7/7] bootargs: switch globalvar to it's own device 2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD ` (4 preceding siblings ...) 2013-01-25 23:55 ` [PATCH 6/7] bootm: " Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 ` Jean-Christophe PLAGNIOL-VILLARD 2013-01-26 0:45 ` [PATCH 1/7] params: allow to access first sub-device and params via env Alexander Aring 6 siblings, 0 replies; 13+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 23:55 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..d82d853 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 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"); -- 1.7.10.4 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/7] params: allow to access first sub-device and params via env 2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD ` (5 preceding siblings ...) 2013-01-25 23:55 ` [PATCH 7/7] bootargs: " Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-26 0:45 ` Alexander Aring 6 siblings, 0 replies; 13+ messages in thread From: Alexander Aring @ 2013-01-26 0:45 UTC (permalink / raw) To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox Hi, On Sat, Jan 26, 2013 at 12:55:26AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote: > 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); Need to call 'free(devstr)' before return? > + } > + > + 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 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/7] globalvar: add multiple device support 2013-01-25 23:53 [PATCH 0/7] globalvar: add multiple device support Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-27 10:08 ` Sascha Hauer 2013-01-27 10:38 ` Jean-Christophe PLAGNIOL-VILLARD 1 sibling, 1 reply; 13+ messages in thread From: Sascha Hauer @ 2013-01-27 10:08 UTC (permalink / raw) To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox On Sat, Jan 26, 2013 at 12:53:26AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote: > 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 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 -- 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] 13+ messages in thread
* Re: [PATCH 0/7] globalvar: add multiple device support 2013-01-27 10:08 ` [PATCH 0/7] globalvar: add multiple device support Sascha Hauer @ 2013-01-27 10:38 ` Jean-Christophe PLAGNIOL-VILLARD 2013-01-27 10:56 ` Sascha Hauer 0 siblings, 1 reply; 13+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-27 10:38 UTC (permalink / raw) To: Sascha Hauer; +Cc: barebox On 11:08 Sun 27 Jan , Sascha Hauer wrote: > On Sat, Jan 26, 2013 at 12:53:26AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote: > > 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 > > 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. 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. > > 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] 13+ messages in thread
* Re: [PATCH 0/7] globalvar: add multiple device support 2013-01-27 10:38 ` Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-27 10:56 ` Sascha Hauer 0 siblings, 0 replies; 13+ messages in thread From: Sascha Hauer @ 2013-01-27 10:56 UTC (permalink / raw) To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox On Sun, Jan 27, 2013 at 11:38:56AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote: > On 11:08 Sun 27 Jan , Sascha Hauer wrote: > > On Sat, Jan 26, 2013 at 12:53:26AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote: > > > 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 > > > > 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. > > 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? pcm038_defconfig See the attached patch commit 3bbc0037970e35dab9838980bbd5dfb67cf2dada Author: Sascha Hauer <s.hauer@pengutronix.de> Date: Sun Jan 27 00:53:14 2013 +0100 fix Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> diff --git a/common/bootargs.c b/common/bootargs.c index d82d853..e9248ab 100644 --- a/common/bootargs.c +++ b/common/bootargs.c @@ -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 diff --git a/common/globalvar.c b/common/globalvar.c index d0aa2a3..aa4f8a0 100644 --- a/common/globalvar.c +++ b/common/globalvar.c @@ -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); -- 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] 13+ messages in thread
* [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 0 siblings, 1 reply; 13+ 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] 13+ 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] " Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-13 18:05 ` Jean-Christophe PLAGNIOL-VILLARD 0 siblings, 0 replies; 13+ 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] 13+ messages in thread
end of thread, other threads:[~2013-03-13 18:09 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2013-01-25 23:53 [PATCH 0/7] globalvar: add multiple device support Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 2/7] globalvar: add it's own bus Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 3/7] globalvar: allow to register multiple device Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 4/7] net: switch to global device Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 5/7] dhcp: switch globalvar to it's own device Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 6/7] bootm: " Jean-Christophe PLAGNIOL-VILLARD 2013-01-25 23:55 ` [PATCH 7/7] bootargs: " Jean-Christophe PLAGNIOL-VILLARD 2013-01-26 0:45 ` [PATCH 1/7] params: allow to access first sub-device and params via env Alexander Aring 2013-01-27 10:08 ` [PATCH 0/7] globalvar: add multiple device support Sascha Hauer 2013-01-27 10:38 ` Jean-Christophe PLAGNIOL-VILLARD 2013-01-27 10:56 ` Sascha Hauer 2013-03-13 18:01 [PATCH 0/7 v2] " 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox