summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEddie Cai <eddie.cai.linux@gmail.com>2017-03-15 14:43:28 (GMT)
committerSimon Glass <sjg@chromium.org>2017-03-16 22:03:43 (GMT)
commit340f418acd1159588b2f0fb50561053212c4247d (patch)
tree2dfbc0fa0fad4407c0b619793820de83e4e522a4
parent2808576491ae36b6ea96743005058f370d936beb (diff)
downloadu-boot-340f418acd1159588b2f0fb50561053212c4247d.tar.xz
spl: Add spl_early_init()
At present malloc_base/_limit/_ptr are not initialised in spl_init() when we call spl_init() in board_init_f(). This is due to a recent change aimed at avoiding overwriting the malloc area set up on some boards by spl_relocate_stack_gd(). However if CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN is not defined, we now skip setting up the memory area in spl_init() which is obviously wrong. To fix this, add a new function spl_early_init() which can be called in board_init_f(). Fixes: b3d2861e (spl: Remove overwrite of relocated malloc limit) Signed-off-by: Eddie Cai <eddie.cai.linux@gmail.com> Rewrote spl_{,early_}init() to avoid duplicate code: Rewrite/expand commit message: Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Eddie Cai <eddie.cai.linux@gmail.com>
-rw-r--r--common/spl/spl.c46
-rw-r--r--include/asm-generic/global_data.h1
-rw-r--r--include/spl.h24
3 files changed, 57 insertions, 14 deletions
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 766fb3d..2bc8b42 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -170,22 +170,20 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
image_entry();
}
-int spl_init(void)
+static int spl_common_init(bool setup_malloc)
{
int ret;
- debug("spl_init()\n");
-/*
- * with CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN we set malloc_base and
- * malloc_limit in spl_relocate_stack_gd
- */
-#if defined(CONFIG_SYS_MALLOC_F_LEN) && \
- !defined(CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN)
+ debug("spl_early_init()\n");
+
+#if defined(CONFIG_SYS_MALLOC_F_LEN)
+ if (setup_malloc) {
#ifdef CONFIG_MALLOC_F_ADDR
- gd->malloc_base = CONFIG_MALLOC_F_ADDR;
+ gd->malloc_base = CONFIG_MALLOC_F_ADDR;
#endif
- gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN;
- gd->malloc_ptr = 0;
+ gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN;
+ gd->malloc_ptr = 0;
+ }
#endif
if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) {
ret = fdtdec_setup();
@@ -202,6 +200,32 @@ int spl_init(void)
return ret;
}
}
+
+ return 0;
+}
+
+int spl_early_init(void)
+{
+ int ret;
+
+ ret = spl_common_init(true);
+ if (ret)
+ return ret;
+ gd->flags |= GD_FLG_SPL_EARLY_INIT;
+
+ return 0;
+}
+
+int spl_init(void)
+{
+ int ret;
+
+ if (!(gd->flags & GD_FLG_SPL_EARLY_INIT)) {
+ ret = spl_common_init(
+ !IS_ENABLED(CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN));
+ if (ret)
+ return ret;
+ }
gd->flags |= GD_FLG_SPL_INIT;
return 0;
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index e02863d..5b356dd 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -127,5 +127,6 @@ typedef struct global_data {
#define GD_FLG_SKIP_RELOC 0x00800 /* Don't relocate */
#define GD_FLG_RECORD 0x01000 /* Record console */
#define GD_FLG_ENV_DEFAULT 0x02000 /* Default variable flag */
+#define GD_FLG_SPL_EARLY_INIT 0x04000 /* Early SPL init is done */
#endif /* __ASM_GENERIC_GBL_DATA_H */
diff --git a/include/spl.h b/include/spl.h
index bde4437..cdd196d 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -213,11 +213,29 @@ int spl_load_image_ext_os(struct spl_image_info *spl_image,
struct blk_desc *block_dev, int partition);
/**
- * spl_init() - Set up device tree and driver model in SPL if enabled
+ * spl_early_init() - Set up device tree and driver model in SPL if enabled
*
* Call this function in board_init_f() if you want to use device tree and
- * driver model early, before board_init_r() is called. This function will
- * be called from board_init_r() if not called earlier.
+ * driver model early, before board_init_r() is called.
+ *
+ * If this is not called, then driver model will be inactive in SPL's
+ * board_init_f(), and no device tree will be available.
+ */
+int spl_early_init(void);
+
+/**
+ * spl_init() - Set up device tree and driver model in SPL if enabled
+ *
+ * You can optionally call spl_early_init(), then optionally call spl_init().
+ * This function will be called from board_init_r() if not called earlier.
+ *
+ * Both spl_early_init() and spl_init() perform a similar function except that
+ * the latter will not set up the malloc() area if
+ * CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN is enabled, since it is assumed to
+ * already be done by a calll to spl_relocate_stack_gd() before board_init_r()
+ * is reached.
+ *
+ * This function will be called from board_init_r() if not called earlier.
*
* If this is not called, then driver model will be inactive in SPL's
* board_init_f(), and no device tree will be available.