|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:" h/ H! G; A( P' F/ e6 H1 _7 ]
/*
- j& G! A# c8 {$ c, B* z$ v2 z& x* Check memory range for valid RAM. A simple memory test determines
' n/ g; P2 h2 O( o( [) [0 K* the actually available RAM size between addresses `base' and# G/ w. K) {- q- x/ A% P
* `base + maxsize'.; w5 y. q: }+ [1 G3 X9 W! ^. f1 {
*/
. [ A% Z1 c* nlong get_ram_size(long *base, long maxsize)# R) \0 K" X {3 L
{( @5 g/ ]2 N8 Y. e
volatile long *addr;
7 Q B$ k. q" E- n; } long save[32];5 u. Z) {. ~5 ?6 t" O7 T2 q; Q8 h
long cnt;
8 f6 W1 \, R" N9 Z+ `9 f long val;( ~! d% G. O& |8 _) |
long size;) O( c1 l) M" I
int i = 0;' S2 `. @$ c. R2 |
6 n( O1 D, s0 M- S/ P8 y2 B
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
5 d- t. u4 |. f4 h addr = base + cnt; /* pointer arith! */
9 d [" ^# H/ w& d3 Y sync ();# Q6 D) t) R8 S& Y% ^# Y# ?/ Q2 ~
save[i++] = *addr;
J/ f* K( c1 s/ K) M sync ();& @/ ]# A( Z0 V+ Y+ ~( i+ S: x
*addr = ~cnt;
! z1 n1 @; o9 i. p8 m) n# [ }9 j+ H1 v' X- r2 n; h# o
! H+ j% f) ^5 L9 {
addr = base;
, i: |$ v' p: B _1 D sync ();! x& A+ z' g' T8 k7 w
save = *addr;
' j7 m C; o2 J6 ]& \ sync ();
$ a8 n- ?; |1 V; H *addr = 0;
2 M% S" y3 Z8 W5 v5 P5 ]/ D, w+ R7 u7 c. E3 m3 O
sync ();' e+ m2 d+ I7 u$ Y+ m) A+ F
if ((val = *addr) != 0) {* T# r0 t' G3 ^1 r
/* Restore the original data before leaving the function.3 C/ x& r& i; E7 L5 R
*/
2 l! D8 a9 I0 J- Y) E4 Y( T sync ();( R/ L& u6 N- N `9 P& ^
*addr = save;
( X4 o$ H# t5 _' \% A for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
, M+ O T6 U; G A& f% X. } addr = base + cnt;
- l1 J" _& E0 h2 c6 C sync ();8 `) j, Y" `) R! K/ ^
*addr = save[--i];
+ i/ c2 o: F* ?; p+ d( _5 { }
9 B" \- E' }4 c5 a; B, R return (0);
* \3 I* h0 l$ A$ g }$ C" H# |# b1 P$ R3 r' O u$ d5 b. c
$ F$ a+ D8 i7 m. Z5 ]8 l for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {' h+ e) ]" a6 i H$ ^
addr = base + cnt; /* pointer arith! */
& q+ z6 P5 c% H7 c, e val = *addr;
( F4 `5 ~$ b4 x9 v. s+ v5 _7 ~ *addr = save[--i];
0 Z1 S: \ J6 O) t6 X if (val != ~cnt) {
( m( p e4 V; i3 L* C7 ~5 E: I" q size = cnt * sizeof (long);
P4 o* F) k: L" T: o6 c. S+ w% Q, j /* Restore the original data before leaving the function.
6 m6 j, T" R& S' C5 f z+ C */- c8 z1 \ j- I. t0 t
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {- V, S& |8 f/ c; j- J H
addr = base + cnt;
6 Y% x" Z8 g- N2 e( m' A *addr = save[--i];7 K1 l# m1 Y8 T/ ?( b$ s7 q
}
7 c( h. y4 `4 e$ [; j" [ return (size);$ g& x6 q- ~6 _
}
2 G; X! c9 G d }
3 k- }) z. [8 z& Z6 R" t3 x; O+ {
return (maxsize);+ J' P0 f- s( ]0 ?2 l1 }7 u
}
8 O9 ]. B3 F/ }int dram_init(void)- h+ ^: I* O& f4 C
{3 Y+ O5 h) b- y
/* dram_init must store complete ramsize in gd->ram_size */2 u7 @/ \: a- c. N1 k
gd->ram_size = get_ram_size(/ W# X# z z8 I3 L3 b7 @8 u
(void *)CONFIG_SYS_SDRAM_BASE,
& X6 o. ?7 \0 l$ f3 ?4 _4 ] CONFIG_MAX_RAM_BANK_SIZE);
. {% _3 D6 \1 p, X# E c. Z return 0;
! ?0 }/ w, I4 H; Q}8 v& K+ r: ?* b3 s$ S6 s
, e4 Z! i" d( O4 ?9 a7 u
8 H' c+ l2 j0 B# i) F& l# Q6 l! A0 |
; }. Z' F( _. L' s. }( V
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
" c; V- {0 Z: f8 n0 V) W4 i t5 K
( o0 P# H! Y; n- e/ G& w' U }% k# q( I9 d" \$ H
( S: x' i9 s. J; h4 y |
|