public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jerry Van Baren <gerald.vanbaren@smiths-aerospace.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] get_ram_size() returns wrong value
Date: Wed, 6 Apr 2005 08:27:21 -0400	[thread overview]
Message-ID: <4253D5A9.6090705@smiths-aerospace.com> (raw)
In-Reply-To: <9b7ca65705040603187af7aa9c@mail.gmail.com>

Daniel Ann wrote:
> Hiya folks,
> 
> Somehow I've missed this before, but just today noticed that u-boot is
> reporting DRAM: 64 MB (BTW, machine is running with 128MB)
> 
> So, again, I had peaked inside the u-boot, and after doing some printf
> statements, I can get it to detect 128MB but I cant seem to get to the
> root of the problem. This is orginal code with my printf.
> 
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>     for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
> printf("*addr(%x)\n",*(addr=base + 0x1000000));
>         addr = base + cnt;  /* pointer arith! */
>         val = *addr;
>         *addr = save[--i];
>         if (val != ~cnt) {
>             size = cnt * sizeof (long);
>             /* Restore the original data before leaving the function.
>              */
>             for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
>                 addr  = base + cnt;
>                 *addr = save[--i];
>             }
>             return (size);
>         }
>     }
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> 
> I can see what the code does. It tries to write ~cnt value (first
> backingup) then read it in to see if it had written it successfully.
> 
> But problem lies at (base + 0x1000000). If u-boot detects val != ~cnt,
> then it will finish the loop right there and return size 64MB. If it
> succeeds, returns 128MB (which is what I have).
> 
> So, natually, I wanted to see what exactly does it change it to, and
> when, hence the printf. But guess WHAT? It reads back perfectly
> correct and return 128MB.
> 
> Do you guys think its timing issue ? Having printf natually adds delay
> factor to the code. Could this be HW problem ? (I can just throw it
> back to the HW people to get it fixed if so :) )
> 
> If I get desperate, I might just leave the dummy printf or hardcode
> the size, but for now, I wouldnt mind diving at it.

Its a memory problem.  Ultimately yes, it is a timing problem.  The 
question is where...
   * Is it your SDRAM initialization?
   * Is it a hardware/layout problem?
     * Are the address line lengths close to the same length?
     * Are the data line lengths close to the same length?
     * Is it a termination resistor problem (missing/wrong value)?
   * Is it the SDRAM itself?

Note that, with your printf(), you are repeatedly reading the memory at 
your boundary case address as well as changing the timing.  You are also 
doing a side-effect assignment to "addr" which gets discarded on the 
next line.

For identifying and debugging memory problems, those are bad practices. 
  Quite often a memory failure will show up on the first read, but be 
fine after that (which is apparently what you are seeing).  By doing 
multiple reads, you are throwing away any information you would have 
otherwise gleaned from the print statement (which may not be much, but 
hey, don't throw it away, it's all you have!).

My suggestion:

     for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
         addr = base + cnt;  /* pointer arith! */
         val = *addr;
         *addr = save[--i];
         if (val != ~cnt) {
printf("*addr %08X => %04X != %04X\n",addr,val,~cnt);
             size = cnt * sizeof (long);
             /* Restore the original data before leaving the function.
              */
             for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
                 addr  = base + cnt;
                 *addr = save[--i];
             }
             return (size);
         }
     }

gvb

  parent reply	other threads:[~2005-04-06 12:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-06 10:18 [U-Boot-Users] get_ram_size() returns wrong value Daniel Ann
2005-04-06 10:42 ` Wolfgang Denk
2005-04-06 12:52   ` Daniel Ann
2005-04-06 13:20     ` Wolfgang Denk
2005-04-07  4:33       ` Daniel Ann
2005-04-07 22:21         ` Wolfgang Denk
2005-04-06 12:27 ` Jerry Van Baren [this message]
2005-04-06 13:05   ` Daniel Ann

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=4253D5A9.6090705@smiths-aerospace.com \
    --to=gerald.vanbaren@smiths-aerospace.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox