public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] board_f: save "malloc_base" from zeroing in case of CONFIG_SYS_MALLOC_F_LEN
@ 2015-01-19 17:55 Alexey Brodkin
  2015-01-19 19:21 ` Simon Glass
  2015-01-20  7:07 ` Albert ARIBAUD
  0 siblings, 2 replies; 6+ messages in thread
From: Alexey Brodkin @ 2015-01-19 17:55 UTC (permalink / raw)
  To: u-boot

In case of CONFIG_SYS_MALLOC_F_LEN "malloc_base" is used for early
start-up code and is set very early, typically in "start.S" or "crt1.S".

In current implementation in case of CONFIG_SYS_GENERIC_GLOBAL_DATA all
global data gets zeroed on "board_init_f" entry. But by that time
"malloc_base" could have been set already, which means it will be zeroed
and subsequent C-code will be executed improperly (if executed at all -
if there's no memory mapped to 0 or it is read-only then on some arches
there will be an exception and others will quetly die).

To work-around described situation we just need to make sure
"malloc_base" is saved prior zeroing global data and recovered
afterwards.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@ti.com>
Cc: Masahiro Yamada <yamada.m@jp.panasonic.com>
---
 common/board_f.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/common/board_f.c b/common/board_f.c
index 3a4b32c..ebdba0e 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -999,6 +999,9 @@ static init_fnc_t init_sequence_f[] = {
 void board_init_f(ulong boot_flags)
 {
 #ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+	int malloc_base;
+#endif
 	/*
 	 * For some archtectures, global data is initialized and used before
 	 * calling this function. The data should be preserved. For others,
@@ -1009,12 +1012,25 @@ void board_init_f(ulong boot_flags)
 
 	gd = &data;
 
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+	/*
+	 * "malloc_base" is supposed to be set in the very beginning of start-up
+	 * code (start.S or crt0.S), now we need to preserve it from zeroing.
+	 */
+	malloc_base = gd->malloc_base;
+#endif
+
 	/*
 	 * Clear global data before it is accessed at debug print
 	 * in initcall_run_list. Otherwise the debug print probably
 	 * get the wrong vaule of gd->have_console.
 	 */
 	zero_global_data();
+
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+	/* Restore "malloc_base" value */
+	gd->malloc_base = malloc_base;
+#endif
 #endif
 
 	gd->flags = boot_flags;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-22 17:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-19 17:55 [U-Boot] [PATCH] board_f: save "malloc_base" from zeroing in case of CONFIG_SYS_MALLOC_F_LEN Alexey Brodkin
2015-01-19 19:21 ` Simon Glass
2015-01-20  7:07 ` Albert ARIBAUD
2015-01-20 13:06   ` Alexey Brodkin
2015-01-21  7:23     ` Albert ARIBAUD
2015-01-22 17:57     ` Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox