diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-09-23 12:49:04 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-09-30 10:28:52 +0200 |
commit | 5ee4ad2229b676ff521a1da9b8b32f474450f56c (patch) | |
tree | 2d5526505b47363b78c1b4fb301d9ef08ebc8067 /arch/arm/lib/armlinux.c | |
parent | 28141f9e5a465571cf79505b2fd4b9ae207b9ce3 (diff) | |
download | barebox-5ee4ad2229b676ff521a1da9b8b32f474450f56c.tar.gz barebox-5ee4ad2229b676ff521a1da9b8b32f474450f56c.tar.xz |
environment variables: introduce new helpers
This introduces some new environment variable helpers and updates
the existing ones. Newly introduced are:
getenv_bool: read a bool variable
getenv_ul: read an unsigned long variable
getenev_uint: read an unsigned int variable
getenv_nonempty: like normal getenv, but does return NULL instead of an
empty string
All new helpers take a pointer to the value. This value is only modified
when the variable exists. This allows the following programming scheme:
unsigned int myvalue = sanedefault;
getenv_uint("myvalue", &myvalue);
So without checking the return value myvalue contains the best possible
value.
getenv_ull is updated to this scheme.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/lib/armlinux.c')
-rw-r--r-- | arch/arm/lib/armlinux.c | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/arch/arm/lib/armlinux.c b/arch/arm/lib/armlinux.c index 40a63ea7e1..75d751bb4d 100644 --- a/arch/arm/lib/armlinux.c +++ b/arch/arm/lib/armlinux.c @@ -42,11 +42,9 @@ static struct tag *params; static void *armlinux_bootparams = NULL; -#ifndef CONFIG_ENVIRONMENT_VARIABLES static int armlinux_architecture; static u32 armlinux_system_rev; static u64 armlinux_system_serial; -#endif BAREBOX_MAGICVAR(armlinux_architecture, "ARM machine ID"); BAREBOX_MAGICVAR(armlinux_system_rev, "ARM system revision"); @@ -54,56 +52,41 @@ BAREBOX_MAGICVAR(armlinux_system_serial, "ARM system serial"); void armlinux_set_architecture(int architecture) { -#ifdef CONFIG_ENVIRONMENT_VARIABLES export_env_ull("armlinux_architecture", architecture); -#else armlinux_architecture = architecture; -#endif } int armlinux_get_architecture(void) { -#ifdef CONFIG_ENVIRONMENT_VARIABLES - return getenv_ull("armlinux_architecture"); -#else + getenv_uint("armlinux_architecture", &armlinux_architecture); + return armlinux_architecture; -#endif } void armlinux_set_revision(unsigned int rev) { -#ifdef CONFIG_ENVIRONMENT_VARIABLES export_env_ull("armlinux_system_rev", rev); -#else armlinux_system_rev = rev; -#endif } unsigned int armlinux_get_revision(void) { -#ifdef CONFIG_ENVIRONMENT_VARIABLES - return getenv_ull("armlinux_system_rev"); -#else + getenv_uint("armlinux_system_rev", &armlinux_system_rev); + return armlinux_system_rev; -#endif } void armlinux_set_serial(u64 serial) { -#ifdef CONFIG_ENVIRONMENT_VARIABLES export_env_ull("armlinux_system_serial", serial); -#else armlinux_system_serial = serial; -#endif } u64 armlinux_get_serial(void) { -#ifdef CONFIG_ENVIRONMENT_VARIABLES - return getenv_ull("armlinux_system_serial"); -#else + getenv_ull("armlinux_system_serial", &armlinux_system_serial); + return armlinux_system_serial; -#endif } #ifdef CONFIG_ARM_BOARD_APPEND_ATAG |