All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] Initializing global_data on SuperH before board_init_f() ?
Date: Tue, 15 Aug 2017 23:07:30 +0200	[thread overview]
Message-ID: <20170815230730.680cdcd8@windsurf> (raw)

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

             reply	other threads:[~2017-08-15 21:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15 21:07 Thomas Petazzoni [this message]
2017-08-16  2:39 ` [U-Boot] Initializing global_data on SuperH before board_init_f() ? Lokesh Vutla
2017-08-16  8:47   ` Thomas Petazzoni
2017-08-17 18:30 ` Vladimir Zapolskiy
2017-08-19 10:04   ` Thomas Petazzoni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170815230730.680cdcd8@windsurf \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.