globalvar: Allow to set initial value
Calling globalvar_add_simple() and setting a value is more than common. Add a parameter for the initial value. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
ba3b39d5f0
commit
016082f85e
|
@ -104,8 +104,8 @@ void cfa10036_detect_hw(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
globalvar_add_simple("board.variant");
|
globalvar_add_simple("board.variant", board_name);
|
||||||
setenv("global.board.variant", board_name);
|
|
||||||
pr_info("Booting on a CFA10036 with %s\n", board_name);
|
pr_info("Booting on a CFA10036 with %s\n", board_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,7 @@ static int vexpress_devices_init(void)
|
||||||
devfs_add_partition("nor0", 0x40000, 0x20000, DEVFS_PARTITION_FIXED, "env0");
|
devfs_add_partition("nor0", 0x40000, 0x20000, DEVFS_PARTITION_FIXED, "env0");
|
||||||
|
|
||||||
|
|
||||||
globalvar_add_simple("hostname");
|
globalvar_add_simple("hostname", v2m_init->hostname);
|
||||||
setenv("global.hostname", v2m_init->hostname);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,10 +164,10 @@ err_out:
|
||||||
static int bootm_init(void)
|
static int bootm_init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
globalvar_add_simple("bootm.image");
|
globalvar_add_simple("bootm.image", NULL);
|
||||||
globalvar_add_simple("bootm.oftree");
|
globalvar_add_simple("bootm.oftree", NULL);
|
||||||
if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD))
|
if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD))
|
||||||
globalvar_add_simple("bootm.initrd");
|
globalvar_add_simple("bootm.initrd", NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,21 +23,6 @@
|
||||||
#include <environment.h>
|
#include <environment.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
static int globalvar_set(char* name, char* value)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = globalvar_add_simple(name);
|
|
||||||
|
|
||||||
if (value) {
|
|
||||||
char *tmp = asprintf("global.%s", name);
|
|
||||||
ret = setenv(tmp, value);
|
|
||||||
free(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int do_global(int argc, char *argv[])
|
static int do_global(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
@ -72,7 +57,7 @@ static int do_global(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return globalvar_set(argv[0], value);
|
return globalvar_add_simple(argv[0], value);
|
||||||
}
|
}
|
||||||
|
|
||||||
BAREBOX_CMD_HELP_START(global)
|
BAREBOX_CMD_HELP_START(global)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <globalvar.h>
|
#include <globalvar.h>
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
|
#include <environment.h>
|
||||||
|
#include <generated/utsrelease.h>
|
||||||
|
|
||||||
static struct device_d global_device = {
|
static struct device_d global_device = {
|
||||||
.name = "global",
|
.name = "global",
|
||||||
|
@ -61,9 +63,15 @@ void globalvar_set_match(const char *match, const char *val)
|
||||||
*
|
*
|
||||||
* add a new globalvar named 'name'
|
* 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)
|
static int globalvar_init(void)
|
||||||
|
|
|
@ -36,8 +36,8 @@ EXPORT_SYMBOL(set_reset_source);
|
||||||
/* ensure this runs after the 'global' device is already registerd */
|
/* ensure this runs after the 'global' device is already registerd */
|
||||||
static int init_reset_source(void)
|
static int init_reset_source(void)
|
||||||
{
|
{
|
||||||
globalvar_add_simple("system.reset");
|
globalvar_add_simple("system.reset", reset_src_names[RESET_UKWN]);
|
||||||
set_reset_source(RESET_UKWN);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <param.h>
|
#include <param.h>
|
||||||
|
|
||||||
#ifdef CONFIG_GLOBALVAR
|
#ifdef CONFIG_GLOBALVAR
|
||||||
int globalvar_add_simple(const char *name);
|
int globalvar_add_simple(const char *name, const char *value);
|
||||||
|
|
||||||
int globalvar_add(const char *name,
|
int globalvar_add(const char *name,
|
||||||
int (*set)(struct device_d *dev, struct param_d *p, const char *val),
|
int (*set)(struct device_d *dev, struct param_d *p, const char *val),
|
||||||
|
@ -13,7 +13,7 @@ int globalvar_add(const char *name,
|
||||||
char *globalvar_get_match(const char *match, const char *separator);
|
char *globalvar_get_match(const char *match, const char *separator);
|
||||||
void globalvar_set_match(const char *match, const char *val);
|
void globalvar_set_match(const char *match, const char *val);
|
||||||
#else
|
#else
|
||||||
static inline int globalvar_add_simple(const char *name)
|
static inline int globalvar_add_simple(const char *name, const char *value)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -667,7 +667,7 @@ static void dhcp_global_add(const char *var)
|
||||||
if (!var_global)
|
if (!var_global)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
globalvar_add_simple(var_global);
|
globalvar_add_simple(var_global, NULL);
|
||||||
free(var_global);
|
free(var_global);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue