common/board_init: setup early malloc during crt0
Currently the early malloc initialisation is done partially in
board_init_f_init_reserve(), which configures gd->malloc_base. But it
isn't actually usable until initf_malloc() is called which doesn't
happen until after fdtdec_setup().
This causes an issue when using MULTI_DTB_FIT, as it expects a working
malloc().
The existence of initf_malloc() seems to be a legacy from when this was
less standardised, but nowadays all it does is set gd->malloc_limit and
malloc_ptr, both of which we could just assign directly from
board_init_f_init_reserve().
Make this change so that malloc() will work in fdtdec_setup() and
simplify this early bootflow.
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
diff --git a/common/board_f.c b/common/board_f.c
index 039d6d7..0a4b77d 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -870,7 +870,6 @@
#ifdef CONFIG_TRACE_EARLY
trace_early_init,
#endif
- initf_malloc,
log_init,
initf_bootstage, /* uses its own timer, so does not need DM */
event_init,
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index a061621..b922806 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -2557,17 +2557,6 @@
}
}
-int initf_malloc(void)
-{
-#if CONFIG_IS_ENABLED(SYS_MALLOC_F)
- assert(gd->malloc_base); /* Set up by crt0.S */
- gd->malloc_limit = CONFIG_VAL(SYS_MALLOC_F_LEN);
- gd->malloc_ptr = 0;
-#endif
-
- return 0;
-}
-
void malloc_enable_testing(int max_allocs)
{
malloc_testing = true;
diff --git a/common/init/board_init.c b/common/init/board_init.c
index ed2365d..4610b8a 100644
--- a/common/init/board_init.c
+++ b/common/init/board_init.c
@@ -162,6 +162,8 @@
#if CONFIG_IS_ENABLED(SYS_MALLOC_F)
/* go down one 'early malloc arena' */
gd->malloc_base = base;
+ gd->malloc_limit = CONFIG_VAL(SYS_MALLOC_F_LEN);
+ gd->malloc_ptr = 0;
#if CONFIG_IS_ENABLED(ZERO_MEM_BEFORE_USE)
memset((void *)base, '\0', CONFIG_VAL(SYS_MALLOC_F_LEN));
#endif
diff --git a/include/malloc.h b/include/malloc.h
index 161ccbd..7e01bc2 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -947,9 +947,6 @@
#endif
-/* Set up pre-relocation malloc() ready for use */
-int initf_malloc(void);
-
/* Public routines */
/* Simple versions which can be used when space is tight */