|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
, D" U6 R6 j/ F/*4 c; E$ K* h: a5 S) }0 A; `
* Check memory range for valid RAM. A simple memory test determines
0 c9 k3 W0 W; p/ x9 d9 q4 Z1 m* the actually available RAM size between addresses `base' and
0 z4 B! g4 B( Z C4 a, x/ d: l* `base + maxsize'.* n2 u% e8 n. K
*/1 T% J+ ~% L6 i; m- ?
long get_ram_size(long *base, long maxsize)5 d3 _* y) r5 t% @- E9 X- M
{
; X( j/ y0 h" q- p% ?8 D; c3 O volatile long *addr;9 G3 G/ D; U7 I) h' m- \9 y
long save[32];
6 b7 h1 M4 Q7 J2 Z/ D% h; n4 A long cnt;
9 f7 i2 l. |# M long val;
6 \' M, ]2 R+ g long size;
# x. a5 j. H" R" l int i = 0;0 u0 R$ s! x1 u- E# o5 i
" U& X7 R2 l& n
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {0 V$ }" w8 m2 y* v) p
addr = base + cnt; /* pointer arith! */
1 e' d1 P) w9 N5 ]( R3 G2 w# V2 @, A sync ();8 v, A. U$ z: P+ N3 h
save[i++] = *addr;
8 w; B, e8 l: E4 }# i$ N4 k sync ();5 ~* W t5 i3 s, |/ U7 ^, v, O
*addr = ~cnt;
8 L G+ y. Z4 m& b( X; c/ W; |# @ }" n! \1 x) T& o
. n8 t% U: g% S$ Q
addr = base;
$ H6 r3 T4 w* T; U& A. r- R- J sync ();. J" \1 Y* [4 B# i
save = *addr;
9 }" @) M# B; U sync ();$ ?, f" p' D S/ s( f* a8 \
*addr = 0;
2 f& T0 [! l4 r7 o- J4 ]9 l2 {$ e8 B4 d4 {* J- z
sync ();
9 l; X" r8 G7 \& \+ b0 C if ((val = *addr) != 0) {
. Z+ l4 ^7 d, s+ ]5 o- W0 i /* Restore the original data before leaving the function.
7 L; b1 Z8 E4 e5 X; R5 u; v9 N */: E$ k! J1 f( k1 L
sync ();' G0 [2 B7 @% X r6 a5 \8 T7 p
*addr = save;
- G$ Y9 o9 V, p S* ^ for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
" ~+ [" \9 h# p* J x' J2 U: p addr = base + cnt;+ r' f' }: c- p( m+ g) [( Q- ~
sync ();
0 U7 D( Q) W4 V' n/ v *addr = save[--i];
$ {' K/ }$ X: p: W" n- T4 b }8 x1 }% V( C" V% b) X* d8 R+ v
return (0);4 B, d# Z8 ^# m: b3 p* F5 I8 Q
}
$ V: H7 [7 O5 k
+ i5 Q7 Q6 E: v for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {. G# ~% n0 ?. C" U1 A1 U
addr = base + cnt; /* pointer arith! */, D, S. w( Y1 `( K0 o% @ Q3 W9 F* o
val = *addr;
( ^ }4 P$ f, h* X4 @, G- n; g *addr = save[--i];
1 s8 \ ` C. t" W6 I6 E8 V2 n if (val != ~cnt) {. X! P3 k8 w- B
size = cnt * sizeof (long);
4 x: M' @: a' O% i /* Restore the original data before leaving the function.
& z4 Z. M/ k9 T0 _ */
, V8 D, _& ]8 ^/ l* { for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
( E5 \+ W7 g: E5 N2 k8 g+ A# a addr = base + cnt;% @% V2 Q3 O, B- S
*addr = save[--i];6 F1 c; V8 H, m: s3 y
}. E$ M. g- T4 |6 r, T. j, h5 r$ x
return (size);, h! B1 n1 S$ `! l% g: \
}, c, s$ u) n: ^* }0 z/ T# L' g
}
% r1 ~9 D. F! U/ u' \
8 d# o# Y$ V- V( A return (maxsize);& q3 X8 V& H% ]) y, W) a$ w3 @8 ?5 ?4 X
}$ |' V) w* r6 h0 h$ i8 t
int dram_init(void)
( V$ h/ I8 |/ \( \{
1 |) `9 _2 m) b# S9 E) X /* dram_init must store complete ramsize in gd->ram_size */- g3 m. b! z# a# S, U
gd->ram_size = get_ram_size( r; r( z, D8 f: P9 p& V, u
(void *)CONFIG_SYS_SDRAM_BASE," T `# M% k, w3 [6 j
CONFIG_MAX_RAM_BANK_SIZE);
. g; w+ n. j$ _* U' |( U return 0;
; g% f6 o4 E) T/ j/ s: c0 c}
" i" y0 R( R2 I( d! t5 m- P0 n8 s- D0 X- J3 I
% D. x! Q" H! b6 ]* u' D* J$ K
: e/ c( ^$ r0 D# W7 ~7 n5 m6 X" C: g9 V- ?5 g9 |
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
7 @- o: n+ D& q5 u: j
( s% f+ |9 k: s' v) t8 s t6 Z
0 T9 j9 B, E3 ~
% C$ m" j3 M0 s8 p7 V* i' x |
|