From 5ee4ad2229b676ff521a1da9b8b32f474450f56c Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 23 Sep 2013 12:49:04 +0200 Subject: 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 --- arch/arm/lib/armlinux.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'arch/arm/lib/armlinux.c') 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 -- cgit v1.2.3