diff mbox

[U-Boot] ARM: crt0: Pass malloc base address

Message ID 1447273397-22833-1-git-send-email-festevam@gmail.com
State Superseded
Headers show

Commit Message

Fabio Estevam Nov. 11, 2015, 8:23 p.m. UTC
From: Fabio Estevam <fabio.estevam@freescale.com>

Commit 5ba534d247d418 ("arm: Switch 32-bit ARM to using generic global_data
setup") causes malloc() to fail in SPL.

The reason is that the GD_MALLOC_BASE is not passed anymore.

Restore the code that passes malloc base so that we can have
malloc working in SPL code again.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 arch/arm/lib/crt0.S | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Simon Glass Nov. 11, 2015, 8:26 p.m. UTC | #1
Hi Fabio,

On 11 November 2015 at 13:23, Fabio Estevam <festevam@gmail.com> wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
>
> Commit 5ba534d247d418 ("arm: Switch 32-bit ARM to using generic global_data
> setup") causes malloc() to fail in SPL.
>
> The reason is that the GD_MALLOC_BASE is not passed anymore.
>
> Restore the code that passes malloc base so that we can have
> malloc working in SPL code again.
>
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---
>  arch/arm/lib/crt0.S | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
> index 80548eb..d620126 100644
> --- a/arch/arm/lib/crt0.S
> +++ b/arch/arm/lib/crt0.S
> @@ -87,6 +87,10 @@ ENTRY(_main)
>         mov     sp, r0
>
>         mov     r0, #0
> +#if defined(CONFIG_SYS_MALLOC_F_LEN)
> +       sub     sp, sp, #CONFIG_SYS_MALLOC_F_LEN
> +       str     sp, [r9, #GD_MALLOC_BASE]
> +#endif
>         bl      board_init_f
>
>  #if ! defined(CONFIG_SPL_BUILD)
> --
> 1.9.1
>

Thanks for digging into this. But this should be set up in board_init_f_mem():

#if defined(CONFIG_SYS_MALLOC_F) && \
   (!defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SYS_SPL_MALLOC_START))
   top -= CONFIG_SYS_MALLOC_F_LEN;
   gd->malloc_base = top;
#endif

Is it possible that the #ifdef logic is wrong for your board?

Regardds,
Simon
Albert ARIBAUD Nov. 11, 2015, 8:33 p.m. UTC | #2
Hello Fabio,

On Wed, 11 Nov 2015 18:23:17 -0200, Fabio Estevam <festevam@gmail.com>
wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
> 
> Commit 5ba534d247d418 ("arm: Switch 32-bit ARM to using generic global_data
> setup") causes malloc() to fail in SPL.
> 
> The reason is that the GD_MALLOC_BASE is not passed anymore.

This is the explanation of the SPL fail, but not the /cause/ of it.
IOW, why is GD_MALLOC_BASE not passed any more, and what function or
routine is it not passed any more to?

> Restore the code that passes malloc base so that we can have
> malloc working in SPL code again.
> 
> [...]

> +#if defined(CONFIG_SYS_MALLOC_F_LEN)
> +	sub	sp, sp, #CONFIG_SYS_MALLOC_F_LEN
> +	str	sp, [r9, #GD_MALLOC_BASE]
> +#endif

NAK, as this only papers over the actual issue. Board_init_f_mem should
have set the malloc base in GD. Therefore, rather than doing it again
later, we must determine why it was not properly done earlier.11111

Can you give me the toolchain version, board name and commit ID that I
could use to reproduce the *faulty* build and check the generated code?

Amicalement,
diff mbox

Patch

diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
index 80548eb..d620126 100644
--- a/arch/arm/lib/crt0.S
+++ b/arch/arm/lib/crt0.S
@@ -87,6 +87,10 @@  ENTRY(_main)
 	mov	sp, r0
 
 	mov	r0, #0
+#if defined(CONFIG_SYS_MALLOC_F_LEN)
+	sub	sp, sp, #CONFIG_SYS_MALLOC_F_LEN
+	str	sp, [r9, #GD_MALLOC_BASE]
+#endif
 	bl	board_init_f
 
 #if ! defined(CONFIG_SPL_BUILD)