|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:# ?6 g% C- D& A2 I0 x% e& f
/*
z2 V9 A( z7 v7 f* Check memory range for valid RAM. A simple memory test determines. o: p3 [) g4 N: U2 X
* the actually available RAM size between addresses `base' and
: \9 [( ^7 A+ y3 Q& R; t* `base + maxsize'., J+ b3 [& g& f4 V( f! P+ k9 F
*/6 _+ _ ?) V4 T/ h# P
long get_ram_size(long *base, long maxsize)
$ X+ H' _$ E- x1 q }{' a% {" h" C4 T" N' C1 \3 M8 `
volatile long *addr;
0 S, x+ @, D. d8 w long save[32];# A5 e5 o {; o( J+ K. w; s: q8 O
long cnt;
9 y7 U$ [6 |3 n/ f long val;
) F$ U6 J! ]2 j. b long size;+ x2 i9 }) c, ~' g
int i = 0;) ^8 C& c5 t$ t! Y. ?3 D
- ]& y3 q3 A0 F, c0 L
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {+ r# S- z: t4 b: o% _6 ?7 l, |
addr = base + cnt; /* pointer arith! */6 z) I6 Q: M# M' r6 ~ R8 ~' R# Q
sync ();
+ n! m! T) m$ T; t2 M& o save[i++] = *addr;
! [! o) f5 Y! r E% z2 X sync ();
+ A, M( G3 b: f* ]' E; W *addr = ~cnt;5 N7 `% v# q% b; v- i" j1 A8 J
}: V) t1 _, {& \2 B' w
$ x9 w9 Z( ~8 l4 ?$ o
addr = base;( K+ z" l5 _! t
sync ();% l' h. q. v' g h1 d' p0 V" q
save = *addr;3 M5 G6 _+ o* ]& I# k. g# b: K
sync ();* f* _2 t% v. ^0 I' F1 f, w! i
*addr = 0;4 @+ m# ~7 s% J- k+ T
! j* h: S6 G8 m: Z% k& n& \# E sync ();
( t4 y! b6 Z0 t% T6 I if ((val = *addr) != 0) {1 }! V I9 ~ R% ]- r, m. F4 l
/* Restore the original data before leaving the function.% c# P% z5 |% w- j: ^8 Q
*/) c/ Z. g, O* K4 u0 O1 P
sync ();3 ]1 A) `- F- c$ L/ @
*addr = save; B* @+ Y/ O! i- [! t
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
& |' M& ]8 y) I/ P# ]; n& C addr = base + cnt;
9 r C5 ~" {5 V4 A0 Z sync ();
9 Z4 z9 B% k% Y& C *addr = save[--i];
' h4 V* v6 C# ^$ Z& j; } }
0 J/ i9 t6 h; Q return (0);
3 i8 M8 N- s% O# ?" M }
9 l, v% ?( X9 w8 ?, b7 |9 i
( }8 R8 e: h" X9 Z% ~ for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
1 @4 f4 Q+ m, s0 `7 N addr = base + cnt; /* pointer arith! *// t' Z k5 w# \; V
val = *addr;" O2 E) U& e4 m" R: S; g) R/ g
*addr = save[--i];! _1 \6 U. `2 i$ F6 T, Y( W
if (val != ~cnt) {
+ }9 p( j$ |- l, s size = cnt * sizeof (long);
) _4 b. l1 x$ L. b6 ~5 k /* Restore the original data before leaving the function.
2 U5 K3 ~7 z6 @, z5 |$ K3 Y* R */) R# N5 P* I$ ^, h. O- l
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {8 ]6 T( R2 M& v3 [0 C# d
addr = base + cnt;) d y9 h' `2 D8 l
*addr = save[--i];2 S# ?3 z C! H: w
}
0 B! Y5 V5 b* D& P. y% ] return (size);
& g" O" d6 R* N) y. J/ Q }2 ~' _1 o6 T" g7 }- s( a
}
, D" \5 s6 l5 }4 G0 h4 n/ w% O3 g# X- f+ q3 J7 b- R' w3 E8 I% J
return (maxsize);2 p/ Q1 c2 M, @7 @
}3 q. F! ^' d6 U0 v$ p+ o
int dram_init(void)+ R6 I+ d: o, q. o' N
{+ Z# N! [% ^. Q/ ^7 `5 V
/* dram_init must store complete ramsize in gd->ram_size */
$ ?+ s- ?5 n" B& z% s gd->ram_size = get_ram_size(
7 t5 @5 e9 j, S! s (void *)CONFIG_SYS_SDRAM_BASE,: g0 W) v: I! j1 f4 [, o
CONFIG_MAX_RAM_BANK_SIZE);' U- K+ D' Z( V
return 0;
' }3 V6 c, e2 i}4 U3 f) [! k) ?+ J+ ?
+ V# E( _+ r9 ]7 L3 G; @3 e
1 }8 m1 I6 d( Q: h- O) ?- Z# [) H) F
) W( V6 N) m+ O }! @3 `) ]# I3 Z! A: Q$ d. T' b* \6 Z& z
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!3 O: {& j* [! R: E8 A
1 O$ Z6 p/ r* U& u {( @- e+ k/ Z# }9 W+ Y& P- X
, h! n" T' y( e6 b8 p4 f |
|