[U-Boot] ALERT! >90% of all board configurations BROKEN

Reinhard Meyer
2010-10-26T00:11:02Z

Dear Wolfgang Denk,
> In message<4CC5E865.70003@emk-elektronik.de> you wrote:
>>
>> Grep-ing for CONFIG_SYS_GBL_DATA_SIZE in *.[chsS] Makefile *.ld it
>> seems to me that with "ELF-reloc" active that define is not used
>> anywhere at least in ARM.
>
> Are you sure? My very first smaple sees:
>
> "arch/arm/cpu/arm926ejs/start.S"
>
> 346 /* Set up the stack */
> 347 stack_setup:
> 348 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
> 349 sub sp, r0, #128 /* leave 32 words for abort-stack */
> 350 #ifndef CONFIG_PRELOADER
> 351 sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
> 352 sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */

That is #ifdef-ed away in case of ARM-relocation. Perhaps we should remove
all code that pertains to "WITHOUT_RELOC"... Would make the rest of the code
less obscure...

I changed my board.config like this:
...
/*#define CONFIG_SYS_GBL_DATA_SIZE 128*/ /* 128 bytes for initial data */
...
#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + 0x1000 /*- CONFIG_SYS_GBL_DATA_SIZE*/)
...
and it still compiles. The second line is the only use of GBL_DATA_SIZE,
since that is often set to somewhere in SRAM, it is still ok - even if
set to the end of SRAM it will most likely wrap into the repeated SRAM
image on most SoCs.

in start.S:

/* Set stackpointer in internal RAM to call board_init_f */
call_board_init_f:
ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
ldr r0,=0x00000000
bl board_init_f

in board.c:

void board_init_f (ulong bootflag)
{
bd_t *bd;
init_fnc_t **init_fnc_ptr;
gd_t *id;
ulong addr, addr_sp;

/* Pointer is writable since we allocated a register for it */
gd = (gd_t *) (CONFIG_SYS_INIT_SP_ADDR);

So global data is at CONFIG_SYS_INIT_SP_ADDR, stack goes down from
CONFIG_SYS_INIT_SP_ADDR.

Board maintainers for ARM should be aware that CONFIG_SYS_INIT_SP_ADDR
should point to RAM with enough space for global data above and enough
stack space below.

Best Regards,
Reinhard