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

Simon Glass sjg at chromium.org
Wed Nov 11 22:08:31 CET 2015


Hi Fabio,

On 11 November 2015 at 14:00, Fabio Estevam <festevam at gmail.com> wrote:
> Hi Simon and Albert,
>
> On Wed, Nov 11, 2015 at 6:41 PM, Fabio Estevam <festevam at gmail.com> wrote:
>> Hi Simon,
>>
>> On Wed, Nov 11, 2015 at 6:26 PM, Simon Glass <sjg at chromium.org> wrote:
>>
>>> 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?
>>
>> Good point. Looks like this is the problem indeed.
>>
>> I have manually removed the #ifdef logic just for testing:
>>
>> --- a/common/init/board_init.c
>> +++ b/common/init/board_init.c
>> @@ -50,11 +50,8 @@ ulong board_init_f_mem(ulong top)
>>  #endif
>>         arch_setup_gd(gd_ptr);
>>
>> -#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
>>
>>         return top;
>>  }
>>
>> ,and then malloc() works fine in SPL.
>
> If I change the logic like this then malloc() works:
>
> --- a/common/init/board_init.c
> +++ b/common/init/board_init.c
> @@ -51,7 +51,7 @@ ulong board_init_f_mem(ulong top)
>         arch_setup_gd(gd_ptr);
>
>  #if defined(CONFIG_SYS_MALLOC_F) && \
> -       (!defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SYS_SPL_MALLOC_START))
> +       (defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SYS_SPL_MALLOC_START))
>         top -= CONFIG_SYS_MALLOC_F_LEN;
>         gd->malloc_base = top;
>  #endif
>
>
> Shouldn't we test for defined(CONFIG_SPL_BUILD) instead of
> !defined(CONFIG_SPL_BUILD)?

That test is intended to avoid setting up simple malloc() if we plan
to use full malloc() in SPL. Of course, full malloc() is set up a
little later (in spl_init()). But we should not need both - either we
use simple malloc() or full malloc().

But for your board I see:

$ grep CONFIG_SYS_SPL_MALLOC_SIZE b/mx6sabresd_spl/u-boot.cfg
#define CONFIG_SYS_SPL_MALLOC_SIZE 0x3200000

So you will not be able to use simple malloc(). I'd suggest calling
spl_init() from board_init_f() if you need malloc() there. But it
presumably needs to be done after you have SDRAM up. So perhaps
consider removing some things from board_init_f() and put them in
spl_board init()?

Regards,
Simon


More information about the U-Boot mailing list