summaryrefslogtreecommitdiffstats
path: root/common/startup.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-01-20 15:54:08 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2013-01-20 16:33:03 +0100
commit0e18d5ae7ff82a455c0d46291d67a894b86b82a1 (patch)
tree56c2814486c29b30cc1394bcc8cd4fa1d6b74d9f /common/startup.c
parent0bbb021b48b62a4e1e4c28bb54d494745034725a (diff)
downloadbarebox-0e18d5ae7ff82a455c0d46291d67a894b86b82a1.tar.gz
defaultenv loading: rework to use less ifdefs/defines
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/startup.c')
-rw-r--r--common/startup.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/common/startup.c b/common/startup.c
index ecb5691..52a8996 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -34,6 +34,7 @@
#include <linux/stat.h>
#include <envfs.h>
#include <asm/sections.h>
+#include <uncompress.h>
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
__barebox_initcalls_end[];
@@ -41,32 +42,35 @@ extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
#ifdef CONFIG_DEFAULT_ENVIRONMENT
#include "barebox_default_env.h"
-#ifdef CONFIG_DEFAULT_ENVIRONMENT_COMPRESSED
-#include <uncompress.h>
-void *defaultenv;
-#else
-#define defaultenv default_environment
-#endif
-
static int register_default_env(void)
{
-#ifdef CONFIG_DEFAULT_ENVIRONMENT_COMPRESSED
int ret;
- void *tmp;
+ void *defaultenv;
- tmp = xzalloc(default_environment_size);
- memcpy(tmp, default_environment, default_environment_size);
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_COMPRESSED)) {
+ void *tmp = malloc(default_environment_size);
- defaultenv = xzalloc(default_environment_uncompress_size);
+ if (!tmp)
+ return -ENOMEM;
- ret = uncompress(tmp, default_environment_size, NULL, NULL,
- defaultenv, NULL, uncompress_err_stdout);
+ memcpy(tmp, default_environment, default_environment_size);
- free(tmp);
+ defaultenv = xzalloc(default_environment_uncompress_size);
+
+ ret = uncompress(tmp, default_environment_size,
+ NULL, NULL,
+ defaultenv, NULL, uncompress_err_stdout);
+
+ free(tmp);
+
+ if (ret) {
+ free(defaultenv);
+ return ret;
+ }
+ } else {
+ defaultenv = (void *)default_environment;
+ }
- if (ret)
- return ret;
-#endif
add_mem_device("defaultenv", (unsigned long)defaultenv,
default_environment_uncompress_size,