|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
% [! Y3 w; R; g9 [) L4 ]: l/*
# N& `+ Y6 }# z4 k! f T* Check memory range for valid RAM. A simple memory test determines1 b5 F& f" M1 o7 S/ {) H' ~
* the actually available RAM size between addresses `base' and
% s p9 j$ `3 ]) R* `base + maxsize'.
, ~& [4 r" I( B n( X% I*/
( @' F" T& n/ H1 Zlong get_ram_size(long *base, long maxsize)" p8 ?2 K6 T Z$ F* x" u; R0 b6 W' h
{
5 V- G8 }/ D5 R3 m, R volatile long *addr;- h% C2 o* B( M* _9 v' D6 k
long save[32];0 |! ?, |3 _' E3 G2 p ]
long cnt;* n6 q; ~" ^& i8 f2 p# E6 j/ V
long val;
) E Y! @' |, K; @* O. x long size;
1 K9 w7 J/ ~4 w6 X) d s: @ int i = 0;/ i, j" L. c; K; K' Z
# r" {) p! W% `% y+ Y) t& G! C
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
% l; \% b. E8 O0 j- b addr = base + cnt; /* pointer arith! */& z0 {9 e) P% }
sync ();) o K, ~. B3 A# ~8 P5 M
save[i++] = *addr;& \, y' e9 u. ~ Q( @9 P
sync ();
: E' n) \7 p$ d8 Y/ o, C8 N *addr = ~cnt;1 s/ J2 O. O5 ?
}7 V2 p) _7 L4 e, \5 H: q
) f- y7 o6 u% {2 Q addr = base;) W4 }0 o! R9 q9 T) p# Z
sync ();, t' t5 z* U) G9 h* r
save = *addr;6 a4 D6 ?! g$ K% c$ H
sync ();
- N( Z! \! ?' g( l; A *addr = 0;8 R4 p. |6 ~( l% N: d
, j$ s" r) ?. E" c, Z
sync ();# F- \7 ]0 D8 Z( i
if ((val = *addr) != 0) {
, |1 F5 F$ F6 ~& |, B /* Restore the original data before leaving the function.
$ B! _6 {% S8 ^) m7 n */# D/ c8 ~6 f4 x8 J# ?( e7 F
sync ();
: i; j3 E. \0 U0 }7 c/ [1 X *addr = save;5 T% @& K- E9 C
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {% A/ S6 x5 U4 ]3 X
addr = base + cnt;
$ l( F* E3 f( y/ m sync ();
- m0 n& l$ l0 t8 w# N5 U *addr = save[--i];
4 w" Y7 G# s+ O7 s5 R) Y# M7 I }# ^5 T P; h% j' `4 X( E) H0 Q4 i8 _
return (0);
t6 y" v3 L5 u0 H6 {) f& M }6 T& A, _6 p2 e4 P
/ U; \8 p; o7 S+ h. B1 _9 ~
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
1 X# Y G/ l g0 G addr = base + cnt; /* pointer arith! */! n: |4 l- L- v2 [7 `* d
val = *addr;* |! R5 A q4 p8 ^
*addr = save[--i];+ n/ G: ~# y$ Y; Y9 D
if (val != ~cnt) {& E4 M; l6 H3 ]+ O) q/ V
size = cnt * sizeof (long);
4 N3 x% o4 T N5 C /* Restore the original data before leaving the function." X. R) w2 k3 B
*/
) {( w" J$ h+ }) F9 j E1 } for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {" |7 E7 g. A) b6 {9 v0 k
addr = base + cnt;
! f! X- F! ^: p6 V' a: t *addr = save[--i];: o. U3 o' x0 U8 e/ C
}( E1 b& C. B& s, O) h# @; f
return (size);
7 |& y9 P) m$ @8 s, u4 X% i3 B% f }7 u$ o2 I" J6 {8 z
}) p4 X) M; E3 Q$ d
" }( \) y0 ^4 ~2 W
return (maxsize);: L' t/ i2 Q; n$ W, Z- {0 h
}7 u' C- j, K$ h1 n0 j* @
int dram_init(void)
5 H$ W; b+ b3 b C{
: w/ f( T+ D3 W6 `; R; @ /* dram_init must store complete ramsize in gd->ram_size */2 M: K( w _6 R& h9 t0 m: V1 c2 A
gd->ram_size = get_ram_size(
+ W, a& f4 P. ]+ O (void *)CONFIG_SYS_SDRAM_BASE,0 o6 ^% u. b& m, s! T
CONFIG_MAX_RAM_BANK_SIZE);- e% c1 b6 v& V7 c3 g
return 0;! E* t* C: k8 j, t8 b) M' U7 X6 L
}
) v+ Q) _# R; {
, y8 i5 ~9 b1 U N& b5 L q/ @3 x1 [ U
- f- F% T8 K f
1 @! y3 r) U% TFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
( A' ^. O9 c$ ]
) i7 f3 a3 f0 j
" x" R/ T" q# k; _# P) s, Q; ^; ?8 N5 I1 A% _& I
|
|