|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:3 H0 i: J0 u I" c# ^4 G. Q$ Q k
/*
4 R1 @: n. d* D0 v' M/ J, @* Check memory range for valid RAM. A simple memory test determines
2 L7 s( h6 w+ i4 w4 v+ A# d2 W* the actually available RAM size between addresses `base' and& Q3 M1 U* O% g# ~* \, c
* `base + maxsize'.
3 W5 ?/ ^+ A! S" g* M*/ L9 f$ b; N: I. w
long get_ram_size(long *base, long maxsize)
6 L( [& P$ B1 |, K& W7 `/ J: s7 k$ L{
( S9 N& o( a" Z volatile long *addr;
' Z( D: s2 W x/ Y3 d long save[32];4 ?' U8 w# Q; d& \2 m
long cnt;2 l, n+ ?% K' r! H
long val;
* v/ |# b+ }0 o/ V6 p k- y long size;
4 y* H. d9 _7 _+ S3 x2 e. X int i = 0;
% q5 H [8 ]7 y4 q- i2 v1 J
8 i& S- s; v7 K% f4 Z' v for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
$ q& o& r$ b! _ addr = base + cnt; /* pointer arith! */
! _9 s0 w3 B5 g$ }) Q sync ();
) a2 V8 n6 B/ o; D% ^6 ? save[i++] = *addr;
1 d# G) T* [; q7 v5 g% Y sync ();- l6 q! H* ]+ s; d5 d. `
*addr = ~cnt;6 ^- H7 c- y! l4 K
}/ N8 p/ `& V W* H5 \7 f: q
6 {# E6 i, }; y( `2 v( m$ g addr = base;4 v/ Y: ]/ G/ w; I" b
sync ();; L% {3 l m5 n2 V" b
save = *addr;
5 L, s& n8 q( P5 A, l2 ?5 w9 y sync ();
7 V/ u5 s. l% R- ~1 d *addr = 0;
4 a3 d; [1 ^# \' R
5 k: L/ v/ k1 [; |# K# r$ {+ z6 |* } sync ();
' q' V4 ^2 i0 u1 j3 @ if ((val = *addr) != 0) {
% a) z; ~6 u ^, E /* Restore the original data before leaving the function.
4 y$ | E& m7 J6 p2 _ */* Q. {" U% M6 \8 N: b
sync ();* j0 Q [4 r0 P( J" k0 e( \& ~
*addr = save;
# J& P V- I; L1 h for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {- d! l3 _4 T0 F( f. l) F1 T
addr = base + cnt;! d. c5 X) n4 m# g% v: \+ n9 F' ], P
sync ();. s" K- j& V9 }# ?4 A3 I* L0 R
*addr = save[--i];& {& ]0 ?" ]' C" j% J
}
6 h1 d! G* H0 f return (0);
+ b/ x% E3 \ ~" a9 d7 g }* U+ u( x3 y# _1 `. d6 H* I' W
e1 P2 {( G% f% I$ g, A$ D6 G
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {! P- J. K! J2 s
addr = base + cnt; /* pointer arith! */8 _, C& _3 F0 a, a" Y
val = *addr;
* k) w# w# T0 W) x+ J g0 r7 @ *addr = save[--i];
+ p5 _3 b# I3 q0 y# N if (val != ~cnt) {8 w! w& h; f2 B ?" S4 o" c8 t
size = cnt * sizeof (long);
' d! B) U- V% S' m- K( h /* Restore the original data before leaving the function.
" u1 G# v2 m0 ` */; n9 l: `4 D+ b1 n* C4 r. ^
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {7 a; m$ F; k9 g" N7 o
addr = base + cnt;
! i* r$ x8 a, f6 Q& a i *addr = save[--i];* J1 b4 u' r! H
}/ B6 {; m9 |: n }3 f/ o" X
return (size);
1 ^9 `% v" X$ v* B4 E5 a4 U }
& T$ ~" T% }, Q' ^ }7 f6 w, k# U0 L" A% t n2 l. Q' w. |
' u5 m- c% @5 q' J4 t' f; W
return (maxsize);; \9 {2 Y4 W9 |. x: t+ L: W
}
5 h. b& q" M. ?" ?2 Bint dram_init(void), f( n/ K9 \5 D, p( J3 T P$ x
{
: {- K8 j) \3 t+ u9 C /* dram_init must store complete ramsize in gd->ram_size */
/ M0 q$ S3 d, N% Y _% a! ] gd->ram_size = get_ram_size(
5 ~5 T) H8 R8 H3 n: O0 K! l (void *)CONFIG_SYS_SDRAM_BASE,* o9 j( `& i' |; D" f
CONFIG_MAX_RAM_BANK_SIZE);* V& V6 f- z8 ` L: K
return 0;
5 {# y% z/ H; [4 }4 ?}! T/ O8 L1 [$ A' m# k& m
1 [0 w/ P1 a/ i! I/ r
9 [8 @) \' p4 E, g+ i/ @: u" p; n1 c+ _- b
& {0 L( c" v. y8 KFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!6 ~' u$ m# \. A
8 {, k: r4 E R/ n2 {" I
& R# I5 G, T0 e& h2 |& m" S3 y+ G; D! Z2 f& c" m4 }& t |
|
|