diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-09-05 10:39:22 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-09-05 10:39:22 +0200 |
commit | 1729b1798e1bfd4614a9cf7cf651cee8b6923283 (patch) | |
tree | 0eab8d4a22e0bc795f15c3062500a420d801ef4c /common | |
parent | 8f9d4007c53cefc513619b83b5b81b146423b11b (diff) | |
parent | 338b6e7edc054523e2cc0dec77ab3aa1716a385f (diff) | |
download | barebox-1729b1798e1bfd4614a9cf7cf651cee8b6923283.tar.gz barebox-1729b1798e1bfd4614a9cf7cf651cee8b6923283.tar.xz |
Merge branch 'for-next/boardinfo'
Conflicts:
arch/mips/boards/qemu-malta/init.c
commands/bootm.c
drivers/of/base.c
Diffstat (limited to 'common')
-rw-r--r-- | common/Kconfig | 2 | ||||
-rw-r--r-- | common/globalvar.c | 19 | ||||
-rw-r--r-- | common/misc.c | 67 | ||||
-rw-r--r-- | common/reset_source.c | 4 | ||||
-rw-r--r-- | common/version.c | 2 |
5 files changed, 76 insertions, 18 deletions
diff --git a/common/Kconfig b/common/Kconfig index 6322d9dcdb..dd705782ab 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -353,7 +353,7 @@ config HUSH_FANCY_PROMPT prompt "allow fancy hush prompts" help Allow to set PS1 from the command line. PS1 can have several escaped commands - like \h for CONFIG_BOARDINFO or \w for the current working directory. + like \h for the 'model' string or \w for the current working directory. config HUSH_GETOPT bool diff --git a/common/globalvar.c b/common/globalvar.c index abcd881adf..edb66ddca6 100644 --- a/common/globalvar.c +++ b/common/globalvar.c @@ -2,6 +2,9 @@ #include <malloc.h> #include <globalvar.h> #include <init.h> +#include <environment.h> +#include <magicvar.h> +#include <generated/utsrelease.h> static struct device_d global_device = { .name = "global", @@ -61,15 +64,25 @@ void globalvar_set_match(const char *match, const char *val) * * add a new globalvar named 'name' */ -int globalvar_add_simple(const char *name) +int globalvar_add_simple(const char *name, const char *value) { - return globalvar_add(name, NULL, NULL, 0); + int ret; + + ret = globalvar_add(name, NULL, NULL, 0); + if (ret && ret != -EEXIST) + return ret; + + return dev_set_param(&global_device, name, value); } static int globalvar_init(void) { register_device(&global_device); + globalvar_add_simple("version", UTS_RELEASE); + return 0; } -postconsole_initcall(globalvar_init); +pure_initcall(globalvar_init); + +BAREBOX_MAGICVAR_NAMED(global_version, global.version, "The barebox version"); diff --git a/common/misc.c b/common/misc.c index 806649431d..f73f4cfe99 100644 --- a/common/misc.c +++ b/common/misc.c @@ -18,6 +18,10 @@ #include <common.h> #include <errno.h> +#include <malloc.h> +#include <magicvar.h> +#include <globalvar.h> +#include <environment.h> int errno; EXPORT_SYMBOL(errno); @@ -126,19 +130,60 @@ EXPORT_SYMBOL(perror); void (*do_execute)(void *func, int argc, char *argv[]); EXPORT_SYMBOL(do_execute); -static const char *boardinfo; +static char *model; -const char *barebox_boardinfo(void) +/* + * The model is the verbose name of a board. It can contain + * whitespaces, uppercase/lowcer letters, digits, ',', '.' + * '-', '_' + */ +void barebox_set_model(const char *__model) +{ + if (IS_ENABLED(CONFIG_GLOBALVAR)) { + globalvar_add_simple("model", __model); + } else { + free(model); + model = xstrdup(__model); + } +} +EXPORT_SYMBOL(barebox_set_model); + +const char *barebox_get_model(void) +{ + if (IS_ENABLED(CONFIG_GLOBALVAR)) + return getenv("global.model"); + + return model; +} +EXPORT_SYMBOL(barebox_get_model); + +BAREBOX_MAGICVAR_NAMED(global_model, global.model, "Product name of this hardware"); + +static char *hostname; + +/* + * The hostname is supposed to be the shortname of a board. It should + * contain only lowercase letters, numbers, '-', '_'. No whitespaces + * allowed. + */ +void barebox_set_hostname(const char *__hostname) { - if (boardinfo) - return boardinfo; + if (IS_ENABLED(CONFIG_GLOBALVAR)) { + globalvar_add_simple("hostname", __hostname); + } else { + free(hostname); + hostname = xstrdup(__hostname); + } +} - boardinfo = of_get_model(); - if (boardinfo) - boardinfo = xstrdup(boardinfo); - else - boardinfo = CONFIG_BOARDINFO; +const char *barebox_get_hostname(void) +{ + if (IS_ENABLED(CONFIG_GLOBALVAR)) + return getenv("global.hostname"); - return boardinfo; + return hostname; } -EXPORT_SYMBOL(barebox_boardinfo); +EXPORT_SYMBOL(barebox_get_hostname); + +BAREBOX_MAGICVAR_NAMED(global_hostname, global.hostname, + "shortname of the board. Also used as hostname for DHCP requests"); diff --git a/common/reset_source.c b/common/reset_source.c index 2a7f9ff6cc..fdc30f4853 100644 --- a/common/reset_source.c +++ b/common/reset_source.c @@ -36,8 +36,8 @@ EXPORT_SYMBOL(set_reset_source); /* ensure this runs after the 'global' device is already registerd */ static int init_reset_source(void) { - globalvar_add_simple("system.reset"); - set_reset_source(RESET_UKWN); + globalvar_add_simple("system.reset", reset_src_names[RESET_UKWN]); + return 0; } diff --git a/common/version.c b/common/version.c index e21dbbedfa..79b2a54b97 100644 --- a/common/version.c +++ b/common/version.c @@ -9,5 +9,5 @@ EXPORT_SYMBOL(version_string); void barebox_banner (void) { pr_info("\n\n%s\n\n", version_string); - pr_info("Board: %s\n", barebox_boardinfo()); + pr_info("Board: %s\n", barebox_get_model()); } |