|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:- ~/ `% U5 {' ]7 L1 `2 s" R6 X
/*
! X/ o/ P' N) z6 K2 [* Check memory range for valid RAM. A simple memory test determines2 f( u+ q: H' O* ]% o! C
* the actually available RAM size between addresses `base' and
' K7 t0 z1 f5 i" W" q* `base + maxsize'.
( N# G- S# w( I*// H$ v& b ~$ f8 B" C C) Z1 x
long get_ram_size(long *base, long maxsize)2 f/ S9 Y. A6 ]$ F5 y" i) J
{
7 i, E' T3 g' @! y volatile long *addr;
. s+ Z8 u/ s1 w+ q& Z long save[32];+ H" | E) u- u: y2 t
long cnt;# Q. j3 n+ C9 X0 E
long val;8 r6 Z6 o9 x* o% c" X3 P) w$ g# @5 V
long size;+ a6 y; N6 I% ~
int i = 0;
9 I- c3 m0 x7 N: y! A. N
2 v1 C1 R x4 t# q" ~ for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {$ J" g& {( c$ h
addr = base + cnt; /* pointer arith! */# @/ Z1 Y* s' `$ U# r3 ]9 n; \" S- S
sync ();
1 K1 N0 Z1 i0 z! ~, j4 L k; z9 R- ` save[i++] = *addr;, v9 z O4 m: n( f
sync ();
. _+ x4 N0 Q+ b *addr = ~cnt;; }* }0 u: s/ t$ @6 H% b& F
}
$ {# j/ T& ]+ e: T( S7 b+ U0 m% P+ J5 z: W9 c5 ~* I9 i* A2 j
addr = base;
- L5 m+ T7 \# R8 _ sync ();6 Y* ]+ @ g- m; ?. ^
save = *addr;+ l7 p& W! }( z
sync ();
; p U) F: a& g c& A; z8 Y. | *addr = 0;) ]- P" Z5 f0 K5 n
6 S1 C6 Z( d6 g; q: z
sync ();
) ]0 j- m+ _% K- D, i% g C4 o, F if ((val = *addr) != 0) {8 [, j! i% G# g( H8 v
/* Restore the original data before leaving the function.4 [# F; d5 u) v. F/ }" V
*/) o/ ?1 V& G+ H) P/ z9 J+ o" \
sync ();
0 @8 y0 i1 S# d& W: \; C- y3 W *addr = save;
# a8 U: W! |5 x. s8 C) T/ P for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
% m* F3 @8 E& S5 I n/ f: m2 J* V addr = base + cnt;
# l% b2 _ l c' B ~ sync ();
- V/ n6 S6 w! N' Y& E# \# z& S *addr = save[--i];
& F: t1 t: p) a9 I8 E }
8 W) T( {6 X% Z* O& F4 z return (0);9 H& h, M, l1 W
}
/ t' R4 k$ E; y/ y5 r( T
2 o H7 ~1 g7 @: q! o( c: `/ l for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
5 e0 t5 l" q0 z/ m3 T0 I$ ? addr = base + cnt; /* pointer arith! */
; I3 G. L' |% V9 i! H$ C: X val = *addr;8 b G0 e/ {4 a$ P% |- z
*addr = save[--i];
5 j- O2 Z8 x4 n if (val != ~cnt) {
6 i) q6 ^6 q c) j$ S size = cnt * sizeof (long);0 ?( a0 Q' k& T/ @" J
/* Restore the original data before leaving the function.
# q ]5 M: Z* h" W */, l! Y# L/ ?* p- J9 y9 [
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
# n* k# h8 o+ K, d! ~ addr = base + cnt;* Q& J f6 [) z% W) T$ |' J) W
*addr = save[--i];! A/ [* L, ~7 S% {3 j8 a
}
2 Y" X8 Q" p1 K! G; M, \ return (size);
# V" x7 J2 D/ d! H' I# t }# f b; E0 x6 d8 u0 W# L
} x. Z Y; R( q) @+ s
. d5 b5 a1 G: t# Z1 Y return (maxsize);. O( m- y1 w" B$ \+ `6 C; A
}% b2 P; F1 H: W! O
int dram_init(void)1 J7 S* a' H8 r3 k
{+ I# U/ S+ I |$ h. O) b3 J
/* dram_init must store complete ramsize in gd->ram_size */
8 `3 Y! ~& }! y2 y J gd->ram_size = get_ram_size(4 ?0 y+ a. r4 E7 P' W/ c# m9 ?
(void *)CONFIG_SYS_SDRAM_BASE,
/ X/ ^7 w$ M7 d CONFIG_MAX_RAM_BANK_SIZE);! R( w7 R9 c) U- G( l% E
return 0;
2 Z& e7 l5 k% k: X1 Z} Z* _, i; k/ ~
! m. d j# c Y% n3 e# B: Y- S* h7 y8 \$ a$ z- d
3 u- B+ N8 B+ R; D
`6 c- d* o, b; q1 |5 R' m, rFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!8 o+ _7 J, X+ t, Q0 k% w
' f. z: @! h1 }7 y8 K( g; n
1 ^; Z- R. {8 z9 [7 K. t# n
6 ^& d' k" _) ^0 b |
|