diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-11-16 14:01:34 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-11-16 14:01:34 +0100 |
commit | 856f60dbd157126241cf9033514137849bb5ca22 (patch) | |
tree | fca1784ef63b89a78127a0f4d1340f90eedd6848 /common | |
parent | ec78bea331e195fff267ae949cee4777ef1add56 (diff) | |
parent | f4ca20c4d27751ee749f382cfd4949d825534fce (diff) | |
download | barebox-856f60dbd157126241cf9033514137849bb5ca22.tar.gz barebox-856f60dbd157126241cf9033514137849bb5ca22.tar.xz |
Merge branch 'for-next/misc'
Conflicts:
commands/Makefile
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/complete.c | 12 | ||||
-rw-r--r-- | common/env.c | 121 | ||||
-rw-r--r-- | common/partitions.c | 3 | ||||
-rw-r--r-- | common/resource.c | 10 | ||||
-rw-r--r-- | common/startup.c | 4 | ||||
-rw-r--r-- | common/uimage.c | 2 |
6 files changed, 79 insertions, 73 deletions
diff --git a/common/complete.c b/common/complete.c index 32d0d194b7..9206ef02a5 100644 --- a/common/complete.c +++ b/common/complete.c @@ -208,7 +208,7 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval) { struct device_d *dev; struct variable_d *var; - struct env_context *c, *current_c; + struct env_context *c; char *instr_param; int len; char end = '='; @@ -225,21 +225,23 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval) instr_param = strchr(instr, '.'); len = strlen(instr); - current_c = get_current_context(); - for(var = current_c->local->next; var; var = var->next) { + c = get_current_context(); + list_for_each_entry(var, &c->local, list) { if (strncmp(instr, var_name(var), len)) continue; string_list_add_asprintf(sl, "%s%s%c", begin, var_name(var), end); } - for (c = get_current_context(); c; c = c->parent) { - for (var = c->global->next; var; var = var->next) { + c = get_current_context(); + while (c) { + list_for_each_entry(var, &c->global, list) { if (strncmp(instr, var_name(var), len)) continue; string_list_add_asprintf(sl, "%s%s%c", begin, var_name(var), end); } + c = c->parent; } if (instr_param) { diff --git a/common/env.c b/common/env.c index 1b2a7c25ad..33a871f7eb 100644 --- a/common/env.c +++ b/common/env.c @@ -30,23 +30,36 @@ #include <init.h> #include <environment.h> -#define VARIABLE_D_SIZE(name, value) (sizeof(struct variable_d) + strlen(name) + strlen(value) + 2) +static struct env_context root = { + .local = LIST_HEAD_INIT(root.local), + .global = LIST_HEAD_INIT(root.global), +}; -static struct env_context *context; +static struct env_context *context = &root; /** * Remove a list of environment variables * @param[in] v Variable anchor to remove */ -static void free_variables(struct variable_d *v) +static void free_context(struct env_context *c) { - struct variable_d *next; + struct variable_d *v, *tmp; - while (v) { - next = v->next; + list_for_each_entry_safe(v, tmp, &c->local, list) { + free(v->name); + free(v->data); + list_del(&v->list); free(v); - v = next; } + + list_for_each_entry_safe(v, tmp, &c->global, list) { + free(v->name); + free(v->data); + list_del(&v->list); + free(v); + } + + free(c); } /** Read back current context */ @@ -58,19 +71,14 @@ EXPORT_SYMBOL(get_current_context); /** - * FIXME + * Create a new variable context and put it on the stack */ int env_push_context(void) { struct env_context *c = xzalloc(sizeof(struct env_context)); - c->local = xzalloc(VARIABLE_D_SIZE("", "")); - c->global = xzalloc(VARIABLE_D_SIZE("", "")); - - if (!context) { - context = c; - return 0; - } + INIT_LIST_HEAD(&c->local); + INIT_LIST_HEAD(&c->global); c->parent = context; context = c; @@ -78,10 +86,8 @@ int env_push_context(void) return 0; } -postcore_initcall(env_push_context); - /** - * FIXME + * free current variable context and restore the previous one */ int env_pop_context(void) { @@ -89,9 +95,7 @@ int env_pop_context(void) if (context->parent) { c = context->parent; - free_variables(context->local); - free_variables(context->global); - free(context); + free_context(context); context = c; return 0; } @@ -105,7 +109,7 @@ int env_pop_context(void) */ char *var_val(struct variable_d *var) { - return &var->data[strlen(var->data) + 1]; + return var->data; } /** @@ -115,16 +119,18 @@ char *var_val(struct variable_d *var) */ char *var_name(struct variable_d *var) { - return var->data; + return var->name; } -static const char *getenv_raw(struct variable_d *var, const char *name) +static const char *getenv_raw(struct list_head *l, const char *name) { - while (var) { - if (!strcmp(var_name(var), name)) - return var_val(var); - var = var->next; + struct variable_d *v; + + list_for_each_entry(v, l, list) { + if (!strcmp(var_name(v), name)) + return var_val(v); } + return NULL; } @@ -150,12 +156,12 @@ const char *getenv (const char *name) c = context; - val = getenv_raw(c->local, name); + val = getenv_raw(&c->local, name); if (val) return val; while (c) { - val = getenv_raw(c->global, name); + val = getenv_raw(&c->global, name); if (val) return val; c = c->parent; @@ -164,34 +170,35 @@ const char *getenv (const char *name) } EXPORT_SYMBOL(getenv); -static int setenv_raw(struct variable_d *var, const char *name, const char *value) +static int setenv_raw(struct list_head *l, const char *name, const char *value) { - struct variable_d *newvar = NULL; - - if (value) { - newvar = xzalloc(VARIABLE_D_SIZE(name, value)); - strcpy(&newvar->data[0], name); - strcpy(&newvar->data[strlen(name) + 1], value); - } + struct variable_d *v; - while (var->next) { - if (!strcmp(var->next->data, name)) { + list_for_each_entry(v, l, list) { + if (!strcmp(v->name, name)) { if (value) { - newvar->next = var->next->next; - free(var->next); - var->next = newvar; + free(v->data); + v->data = xstrdup(value); + return 0; } else { - struct variable_d *tmp; - tmp = var->next; - var->next = var->next->next; - free(tmp); + list_del(&v->list); + free(v->name); + free(v->data); + free(v); + return 0; } } - var = var->next; } - var->next = newvar; + + if (value) { + v = xzalloc(sizeof(*v)); + v->name = xstrdup(name); + v->data = xstrdup(value); + list_add_tail(&v->list, l); + } + return 0; } @@ -199,8 +206,8 @@ int setenv(const char *_name, const char *value) { char *name = strdup(_name); char *par; - struct variable_d *var; int ret = 0; + struct list_head *list; if (value && !*value) value = NULL; @@ -224,12 +231,12 @@ int setenv(const char *_name, const char *value) goto out; } - if (getenv_raw(context->global, name)) - var = context->global; + if (getenv_raw(&context->global, name)) + list = &context->global; else - var = context->local; + list = &context->local; - ret = setenv_raw(var, name, value); + ret = setenv_raw(list, name, value); out: free(name); @@ -239,11 +246,11 @@ EXPORT_SYMBOL(setenv); int export(const char *varname) { - const char *val = getenv_raw(context->local, varname); + const char *val = getenv_raw(&context->local, varname); if (val) { - setenv_raw(context->global, varname, val); - setenv_raw(context->local, varname, NULL); + setenv_raw(&context->global, varname, val); + setenv_raw(&context->local, varname, NULL); } return 0; } diff --git a/common/partitions.c b/common/partitions.c index 0e42937e4c..24310a3a4f 100644 --- a/common/partitions.c +++ b/common/partitions.c @@ -28,6 +28,7 @@ #include <asm/unaligned.h> #include <disks.h> #include <dma.h> +#include <filetype.h> struct partition { uint64_t first_sec; @@ -85,7 +86,7 @@ static void __maybe_unused try_dos_partition(struct block_device *blk, goto on_error; } - if ((buffer[510] != 0x55) || (buffer[511] != 0xAA)) { + if (is_fat_or_mbr(buffer, NULL) != filetype_mbr) { dev_info(blk->dev, "No partition table found\n"); goto on_error; } diff --git a/common/resource.c b/common/resource.c index da631d3997..ea6abe88e3 100644 --- a/common/resource.c +++ b/common/resource.c @@ -101,6 +101,8 @@ int release_region(struct resource *res) struct resource iomem_resource = { .start = 0, .end = 0xffffffff, + .name = "iomem", + .children = LIST_HEAD_INIT(iomem_resource.children), }; /* @@ -111,11 +113,3 @@ struct resource *request_iomem_region(const char *name, { return request_region(&iomem_resource, name, start, end); } - -static int iomem_init(void) -{ - init_resource(&iomem_resource, "iomem"); - - return 0; -} -postcore_initcall(iomem_init); diff --git a/common/startup.c b/common/startup.c index 78926c9963..7bb3c73c12 100644 --- a/common/startup.c +++ b/common/startup.c @@ -100,7 +100,9 @@ void start_barebox (void) initcall < __barebox_initcalls_end; initcall++) { debug("initcall-> %pS\n", *initcall); result = (*initcall)(); - debug("initcall<- %pS (%d)\n", *initcall, result); + if (result) + pr_err("initcall %pS failed: %s\n", *initcall, + strerror(-result)); } debug("initcalls done\n"); diff --git a/common/uimage.c b/common/uimage.c index 3a9753459a..344bd61c06 100644 --- a/common/uimage.c +++ b/common/uimage.c @@ -373,7 +373,7 @@ static int uimage_sdram_flush(void *buf, unsigned int len) return len; } -#define BUFSIZ (PAGE_SIZE * 2) +#define BUFSIZ (PAGE_SIZE * 32) struct resource *file_to_sdram(const char *filename, unsigned long adr) { |