|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
- _( l( d6 }& F3 ^' M. B3 C/*7 z- j* _9 @$ A( D" S
* Check memory range for valid RAM. A simple memory test determines
1 I3 \0 q- b0 h8 Q+ F& S" p* the actually available RAM size between addresses `base' and
1 e* U: ~# b3 I* `base + maxsize'.- I, z9 y ?+ y+ w
*/
( w6 ]! K( z; A9 u: Nlong get_ram_size(long *base, long maxsize)7 W1 V: ~* \8 J
{
1 }$ L3 S" C( L volatile long *addr;
5 Y4 v" b! c0 |- E long save[32];) }, j; D. o1 D4 }8 l# P+ n
long cnt;5 j6 d3 [8 |) v0 O, ?
long val;
5 A; b. D' D$ j6 a long size;
9 p9 _" I1 ~! Z+ `' @* t @8 q int i = 0;
0 s5 x4 v& D% v4 [+ c1 e( ~1 X$ p. j. M* U/ |0 L, {
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
- K. p- {) l- a1 ]8 p- e) V addr = base + cnt; /* pointer arith! */! A; M- k# ] b
sync ();$ T- n4 V& P y/ e+ U
save[i++] = *addr;8 `. @, S" E3 X: B8 r- p3 k- g
sync ();
/ r) z4 z+ @' x2 F *addr = ~cnt;, e9 h) s* ~" n5 _7 A
}
9 h: T! K( J' E
9 y# i, o5 T$ ]* j j. L0 y: c: V addr = base;
7 Q5 q2 J s8 O0 p7 W sync ();
/ V2 K% v: Q5 J: c# p" M0 n1 P save = *addr;" c) ]4 R. B4 U/ x. T% q
sync ();4 G4 F6 w2 I! ^
*addr = 0;- U- |- f3 t. N3 v$ K3 Q
+ _4 o/ c. @' i0 [8 Z! J7 c" j
sync ();
/ D! R6 t; K6 b( l if ((val = *addr) != 0) {. I# ^- c0 v* q. i9 t
/* Restore the original data before leaving the function.) }5 b/ {5 X8 k h4 ]) {
*/ k/ V) W D6 G! n
sync ();' o$ k/ Z( M/ x1 f
*addr = save;
: P+ P/ S! W+ I/ n z( f for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {' V- ?$ N! }6 ~% G/ l" i
addr = base + cnt;' O. j3 ^& B* U/ O- T1 r
sync ();; ~& \. x% q9 j% M
*addr = save[--i];
7 x& c1 M' {1 C7 A% E }+ t) T* S5 K0 E5 _: ?' [4 M
return (0);; X/ g9 G. Q7 g1 u B3 v
}
# |0 |4 }0 L* `$ j9 e3 z9 @. z4 x' S) P0 i0 Q7 c
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {- e/ @# i5 N( Y' q& V9 |& I: v
addr = base + cnt; /* pointer arith! */. J9 f" @, s1 r; c" X2 s
val = *addr;8 K2 v4 h6 O1 ^" c* V% T, M2 o
*addr = save[--i];
5 i4 t# V& y3 T& _$ E+ O3 i' j$ l if (val != ~cnt) {% R7 F4 T# Y/ q) z: d! A( q6 H7 c
size = cnt * sizeof (long);
$ ] F7 v6 y2 ~; K+ o$ f8 d /* Restore the original data before leaving the function.5 X5 R, I9 L/ ~+ U; Y! g
*/8 N9 |0 N1 o9 _. h1 f7 t- Y
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {% B( d x5 S" Q) c
addr = base + cnt;% Q7 l o1 c2 |, S2 {5 g+ S
*addr = save[--i];: d1 |8 ~* Z) u) E) {
}: c; w* _: |/ t6 J6 ~
return (size);
, k9 }, h+ p5 J5 i }
: d' m: c2 A: \3 V; Z }' L% y. b4 G& n# w1 m. d7 P
1 i7 Z/ Y' x" R/ S return (maxsize);$ E/ b% s, o0 B( y! H6 U2 D
}
, L. {$ b% W7 h" x$ @" F; a2 dint dram_init(void)5 A; K- Z$ E3 r( ]9 c( {$ t8 M2 ]
{4 j% [, T( ] w
/* dram_init must store complete ramsize in gd->ram_size */; x( v: {; l! s. ]& G0 w
gd->ram_size = get_ram_size(% ~- W) Y' n& Q, N2 l
(void *)CONFIG_SYS_SDRAM_BASE,& Q1 [: w- j0 X: c/ C! y
CONFIG_MAX_RAM_BANK_SIZE);
3 O0 p' F; }9 ]: q2 _ return 0;! i! j0 m4 W5 D( y5 ~3 w' S
}
; K3 H1 B: y0 R( h: w! V
9 O8 F; j: t5 w: r$ k% X/ d; Y; B8 \% y0 `2 f) a8 Z* Y
5 Z' b% G* z% N1 s, D. i
/ I7 r8 y0 L0 e- {+ EFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!$ k" e$ w" }9 l k/ a. x" l, ^, f: Y1 E
# \8 d5 X2 m c7 K h0 |
& f7 o v5 o* I8 V! m
) I; ^. c8 h& Q' \2 H. M/ w' k |
|