[U-Boot-Users] Re: Some puzzles on dram_size()

chris at nanometrics.ca chris at nanometrics.ca
Tue Jan 6 17:28:33 CET 2004


Hi Sam,

Your problem with dram_size() may be that it tests memory
beyond the maxsize given.

     for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
          addr = base + cnt;  /* pointer arith! */

          save[i++] = *addr;
          *addr = ~cnt;
     }

If maxsize = 16M, initial cnt = 4M, so if base = 0,
the first time through the loop, addr = 16M which is
the first address outside of the memory range given
to test.

The reason it usually works is that most boards make the
AM (address mask) in the OR (option register) of the memory
controller specify more memory than they actually need.

This may be the easy way to fix it, however I would say the correct
way would be to change the lines
     for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
     for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
to
     for (cnt = maxsize / sizeof (long) / 2; cnt > 0; cnt >>= 1) {
     for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {

Unfortunately it appears in many board specific versions.

While I'm at it, the entire function should be moved to a file in
the common directory and the function definition changed to
     long int dram_size (long int *base, long int maxsize)

The setting of the MxMR (memory A/B mode register) has nothing
to do with determining the DRAM size and should be done in the
calling function which is board specific.

I know, I'm free to submit a patch, but I'm a combination of
busy and lazy.

Chris





More information about the U-Boot mailing list