public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] Initializing global_data on SuperH before board_init_f() ?
@ 2017-08-15 21:07 Thomas Petazzoni
  2017-08-16  2:39 ` Lokesh Vutla
  2017-08-17 18:30 ` Vladimir Zapolskiy
  0 siblings, 2 replies; 5+ messages in thread
From: Thomas Petazzoni @ 2017-08-15 21:07 UTC (permalink / raw)
  To: u-boot

Hello,

As you probably noticed with the few patches I sent late July, I am
porting U-Boot to an old SH7786 platform. As part of this effort, I
stumbled across a bug: the global_data structure is not initialized to
zero by the SuperH architecture code before calling board_init_f().

The SuperH architecture code defines the global data in
arch/sh/lib/start.S:

        mov.l   ._gd_init, r13          /* global data */
[...]
        mov.l   ._sh_generic_init, r0
        jsr     @r0
[...]
._gd_init:              .long   (_start - GENERATED_GBL_DATA_SIZE)
._sh_generic_init:      .long   board_init_f

So basically, it makes r13 points to the global data (which is expected
on this architecture), and then calls board_init_f().

Hence, we enter board_init_f() with global_data uninitialized, which
have caused me quite some troubles, as I was seeing semi-random
behavior: in various places, we test if a pointer in global_data is
NULL or not to decide to do something (or not). This obviously goes
really bad when global_data contains garbage.

Should we put global_data within the .bss section, so that it gets
zero-initialized automatically? Should we zero-initialize it explicitly?

I've currently worked-around the problem by adding a memset() to zero
of the global_data at the beginning of board_init_f(), but I'd prefer
to find an upstreamable fix.

Thanks!

Thomas Petazzoni
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

end of thread, other threads:[~2017-08-19 10:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-15 21:07 [U-Boot] Initializing global_data on SuperH before board_init_f() ? Thomas Petazzoni
2017-08-16  2:39 ` Lokesh Vutla
2017-08-16  8:47   ` Thomas Petazzoni
2017-08-17 18:30 ` Vladimir Zapolskiy
2017-08-19 10:04   ` Thomas Petazzoni

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