|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
0 D K6 B" I: i5 e4 J/*+ b# K0 F3 w: G9 @' `
* Check memory range for valid RAM. A simple memory test determines
: t% Q- }2 q: ]" j' P; X* the actually available RAM size between addresses `base' and
$ S0 _# r2 C8 ?( o6 I. E# F* `base + maxsize'.
9 M( V9 W) \, ~- ]8 P) _. Q9 u*/
7 W2 i. q* N7 Clong get_ram_size(long *base, long maxsize): C: [0 A. F8 @; T
{
6 p5 N" E5 [" W" ` volatile long *addr;
3 S: }. D. D$ r" Q; B" E( X$ ?( t long save[32];
- A( _+ b/ ]. V& Y long cnt;* m0 E- \* ?7 S( l: L
long val;
# @0 |# F1 I |% u long size;
% x' z, J4 V8 L( j4 c' ? int i = 0;
; t, `# e. L8 M
( b3 y% A' y0 J for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {4 k6 ]0 m8 Q# G. j, c/ g
addr = base + cnt; /* pointer arith! */" d, B1 E; O, R7 Y+ ?3 b3 f
sync ();. j$ w) v5 J4 e8 p1 `8 b+ q# Y [0 i1 N
save[i++] = *addr;
" q4 F* i5 ^, Y4 n- ~, O% k sync ();
/ m/ |7 O o: L. V$ k9 a *addr = ~cnt;* W7 Q) g3 }( d; }! D7 P
}$ i, w0 c2 I3 `, v% P, V
1 Q8 O) o/ c( j7 X$ R addr = base;# [1 I) H5 }/ s% z2 N1 Y, o! ]
sync ();; z `3 h+ s! E8 f2 J1 n2 z1 P
save = *addr;! E+ ~' c0 K* q, A8 o
sync ();% z/ C) x+ m8 {/ ~
*addr = 0;/ U% o1 f+ Q. v' w3 D
9 f; C/ M, t3 i sync ();
/ g0 W; T! D# P& L1 \2 I0 V if ((val = *addr) != 0) {
( e) m7 s! \; U0 \+ F$ Q6 P) z /* Restore the original data before leaving the function.
6 G0 g0 N& C4 s$ O3 x) A; M */
* d: k- k$ C8 c" d1 r M7 a& n sync ();
5 H5 S% X6 y* D' g6 j5 s+ s# _( D *addr = save;
6 Q* e. X+ Y' g0 o for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {0 u8 _& @3 |6 ~/ U/ c
addr = base + cnt;
" z/ i0 w/ Y1 [ c& K6 X sync ();" ]1 v! _2 v! ]$ p8 {$ M
*addr = save[--i];/ T; y# V" p. g0 K
}
1 k* b; y: o2 |7 I' H u& b0 } return (0);2 G& Y$ ]% }% b: p+ o) ]
}2 b2 \: Z4 B3 B" v; q
9 m. Z" ^' ^. k6 o( v for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {$ G$ L" J+ A8 ^& o) v+ T
addr = base + cnt; /* pointer arith! */4 l: L5 K: x5 Y
val = *addr;1 ]2 Q7 {1 D( p n3 H
*addr = save[--i];& z5 b3 n. {8 J
if (val != ~cnt) {
, n9 L% {7 K& p1 x+ | size = cnt * sizeof (long);5 m( B8 t/ s9 ?; D5 R1 N. f) B
/* Restore the original data before leaving the function.
G# C/ z8 N; F- ~+ G */
8 ~" h$ n# Z* i' n' y+ J* a; A) U for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
6 e5 `4 e5 F/ }7 \+ z addr = base + cnt;
' u N1 `! }: d6 u2 q *addr = save[--i];2 m# m, O* a( v
}
% f& a' s% g% {5 r8 N7 y& h return (size);8 _( {( d( @0 W
}9 X: x+ V2 r4 r8 G" x# U$ V9 i; }2 e
}# e, t t6 l! x0 o9 p" d2 I
& w* B8 g3 x1 p, w
return (maxsize);: N# D' G2 K5 u: O N4 a: I
}, N7 V/ m: X. z" {1 T
int dram_init(void)+ t& t7 [0 E# v4 A6 D
{
3 X1 \# l' e- f+ k& e: c /* dram_init must store complete ramsize in gd->ram_size */: R2 x- M( D& G! T* G ^; q0 R/ s
gd->ram_size = get_ram_size(6 D; D# p& n4 k/ f! e9 h
(void *)CONFIG_SYS_SDRAM_BASE,* m, M# I' S9 m. u
CONFIG_MAX_RAM_BANK_SIZE);4 v! z) J5 w% @( O& i) o
return 0;) i& K2 K% J/ R, V# [' V8 B, R* N9 g. M
}' I0 m* X5 H6 e; G3 t. U2 m
; K0 m) @) V& N& H
& f6 `& W5 K& u; a
- B) J- l5 W. |5 Q; c/ n
* C% Q: k) Y: C0 O2 MFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
0 s7 \; `0 }6 l8 G& h
; [" G& c3 O/ F: P5 C$ o
/ B/ F( O) z6 d6 p4 t0 |
+ V4 Y% K4 H5 n- y1 F$ H |
|