|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:1 d( ]. |& Y [3 D" o s: m/ @
/*8 W0 n; E- S+ z" @! k; b U
* Check memory range for valid RAM. A simple memory test determines4 P" m/ T' w. w) B1 Z; J! G) H
* the actually available RAM size between addresses `base' and4 T) v3 ~5 @( t V/ ~: q* h+ O
* `base + maxsize'.! G3 O G0 x2 X
*/
4 ^, C! p n% d0 v5 f5 ^* llong get_ram_size(long *base, long maxsize)
( ]" e! v5 ^! f* |# j( F9 ~0 g4 d{; B$ |$ Q4 g0 w" T- J
volatile long *addr;% A( \, e. V9 S: r
long save[32];1 ?* B. y. N2 N6 E
long cnt;+ r9 }2 ~0 f5 x" v+ ^
long val;% k; W1 {8 `) F
long size;
' q1 \. J% p( x# f z# x, N/ Y int i = 0;$ z% E2 J: p. B$ ]" C6 D
0 n4 X2 u; p* n( d) Z8 n% a
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {. B2 k5 J( s) l: ]
addr = base + cnt; /* pointer arith! */
5 f* _2 j ]% Q) T& ~6 V sync ();# O" O/ \3 C, P0 X- O
save[i++] = *addr;4 n; x; B5 u6 q- S1 f( W. x! K
sync ();
( C8 l7 J8 L. T7 w5 d0 C *addr = ~cnt;0 z% I5 Q( @4 X8 @) j
}; ~& m4 D% D6 f0 K# [% G. ?- p' e
4 X5 q5 u! z( W6 ]4 g% H) v/ {& \
addr = base;$ {; i) g, }! M2 Z; ~. h
sync ();7 r. Q$ ` B9 T1 D: K K: C
save = *addr;
! S+ ^2 s2 W0 C! M& s, g sync ();! u9 J" U3 l" r# q: `% c
*addr = 0;% T$ }: n; G: C6 K8 w; u' L
: c% d' Q1 b: x: A" E2 L sync ();
$ }+ ^: `( Q& O" V if ((val = *addr) != 0) {% h' ?5 M5 v. {* a0 l/ o" o
/* Restore the original data before leaving the function.3 K6 W {, v& q6 _7 R2 N
*/" @0 {3 J9 @* X9 j# x/ w1 o
sync ();8 m h9 Y, o% W& H4 [ a
*addr = save;
3 O" s; X: Q4 x6 i1 W for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {% t; `: U$ p# a2 ^3 W% `& |1 q* d
addr = base + cnt;/ W1 f- j% `; Z8 Q( u
sync ();3 F" `6 E9 S0 M* Q
*addr = save[--i];- n- D ]9 g) d8 |
}
1 M. s& E, {; { return (0);' P, S e$ Z3 V- w
}; Z/ }2 n6 ^# {& V- e1 w
z" [5 l0 k- h' [" `" h3 e
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
8 ~/ O" ?8 L7 r2 C addr = base + cnt; /* pointer arith! */
* ]! U- @5 ]8 r8 L# _ val = *addr;
1 A7 s( n/ H2 P Q# ~& U/ r5 o *addr = save[--i];/ c9 m% y" ?/ W, j$ j3 R2 t% W
if (val != ~cnt) {3 B, W" i5 S# n: Q7 ^; E
size = cnt * sizeof (long);
, s0 s6 |: E% K- q /* Restore the original data before leaving the function. w$ ]2 u: R3 y
*/
$ |6 y3 `' |* H. y* \/ ? for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
/ a. S+ n2 }- `. M# J1 w addr = base + cnt;7 H0 R( C# T6 I) M' d; q7 ]0 ?
*addr = save[--i];
: @4 N2 k! g7 ~ }
6 L% ^2 G v0 G; i return (size);; ~) O! n9 F' {3 S7 a ?' g
}! q& y: j" @# K2 `3 P- Z5 n
} k. r6 ]% N$ H$ G
5 A9 F8 b7 t& U3 |7 ]2 q
return (maxsize);3 W- h. _, N- B% w
}& s6 K( z$ I# W4 z
int dram_init(void)- B5 C5 P+ o% Y# s
{
# F' j {9 M7 W* | /* dram_init must store complete ramsize in gd->ram_size */
+ m8 Q. k5 p1 ?% x8 u3 J' A gd->ram_size = get_ram_size(
9 z) e5 E `! P: {% E9 S (void *)CONFIG_SYS_SDRAM_BASE,
4 `2 T; @. D. E* p) U: } CONFIG_MAX_RAM_BANK_SIZE);
# S+ N- U' ~1 r$ P0 G7 i! J% _& x, {) P return 0;. h+ {* y+ r6 P0 p% o" \
}3 e5 P# ?% {2 O% @" L! C
, G9 s0 @) N1 j& R. Y* p% G' _$ q' X! g$ V
( D- R. q+ z Y V9 y* F$ u
7 F! L9 l% G# _5 X) Q8 y: [& pFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!' r- ^& v+ o1 L, |7 M" F- H
2 U9 g' ]* I1 L- P3 Q% k' u% r& E8 E# C8 l4 k$ b" h
( ?6 T0 o5 V% H, E) ^! Z: s8 f
|
|