|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:; y+ R B' A+ u9 D! J0 l& g
/*
( m+ A( D, n7 y* Check memory range for valid RAM. A simple memory test determines3 r% f' i4 M( ]: z( A
* the actually available RAM size between addresses `base' and
6 M" u8 Q$ X |1 [, W* `base + maxsize'.
9 d! `) L7 ~! \: @6 B) ~/ r; s' g*/* d/ \9 i5 x4 [
long get_ram_size(long *base, long maxsize)+ p, B h$ o% b( g( a7 i
{
3 i2 N3 P& U. ^, U) ~ volatile long *addr;
# f* H t7 y) M* a9 a. o4 i long save[32];. A" I0 Y5 D' m$ ]5 s7 l
long cnt;
& j( k# E7 V9 B' x long val;
% O; T( o6 c- e& K long size;$ R3 l+ V; \& Z3 q* I( N& R$ ~
int i = 0;
- h$ ?/ D+ b8 C2 o6 |9 A( d0 |' E. w. C% y' W( Z9 K
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
" c) z9 x* ~/ x! a. j6 y7 c. f8 R: l addr = base + cnt; /* pointer arith! */
( m! E; V7 P I/ P sync ();
* P' q; e5 F: m0 `8 c, b! s( z6 s save[i++] = *addr;% X! i: A2 [0 E9 u
sync ();* A/ n6 w" g* y! ^
*addr = ~cnt; f6 w) I0 U$ L: l! q& y. C5 x
}2 b' r& {- u+ \8 m7 A
- w3 s& @; ?5 v% ?# b2 x4 j `& y
addr = base;
7 r9 n3 f0 f4 U ?. ~ sync ();
% }6 S; }9 h* ?) Q save = *addr;1 [2 M! F2 m. x* A
sync ();
: M0 p# r# E$ {- d1 t *addr = 0;
% f6 a$ q# n* d4 N0 j
" H- h8 c; p# t3 f, u: H sync ();
6 G; W3 o" Z5 e if ((val = *addr) != 0) {
8 ~" p) `/ r1 U$ C/ y- o /* Restore the original data before leaving the function.
' \5 u' Q4 u$ Z1 `% f */
& U5 l6 d: O5 S' Y1 h3 x sync ();
7 O$ B: z. q* Q; ] *addr = save;& V7 V1 V$ @ n/ |- Z
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {5 M* X/ ?& O( ?/ \; K/ d' L
addr = base + cnt;, I R$ X+ ^8 d+ R- F1 p
sync ();
. d9 ~% C5 x8 {9 z* V *addr = save[--i];
0 ]% V! [# `$ g3 u8 p }1 `& A4 O1 T# X% u, Z0 _
return (0);
( v3 X- N" l* {# U4 C5 K5 M }
# X, Q& x2 f& z/ p6 C( @: I1 V: {+ U- X) W% \
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
0 s5 o2 t7 t1 ~. i: I( s0 O addr = base + cnt; /* pointer arith! */+ g6 J& n$ P, Y" d3 e. k1 x7 V" O
val = *addr;) f" Y+ s D& o
*addr = save[--i];
3 U( @% F- x5 C- C( a2 } if (val != ~cnt) {0 v9 J2 r. ]. X! n$ l
size = cnt * sizeof (long);# I |3 g+ e6 J, K1 f, ~
/* Restore the original data before leaving the function.
9 m! V. J. X4 M1 O e g7 R */
* t9 e2 w* y2 D/ _7 r4 O q/ ? for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {' z/ J" A; n0 J" J
addr = base + cnt;
. y* I$ Q E3 d5 p8 m4 [ *addr = save[--i];
( Q& ^0 o% L& V- b }
% S) e$ _7 q/ B& K! { return (size);1 u E* A! b# g" W
}
) T4 Y: B L* r4 D0 l0 G }
# L- h; d9 k& H7 |" {7 e$ ?$ m0 \# |1 m8 G
return (maxsize);! Y& Z1 ]) l7 z# V6 D
}
$ c$ v, g* e" j$ |0 v! f' J8 Q$ f- Aint dram_init(void)
! D- z3 q$ Z, o6 B3 ]7 F: S{
( k2 ? q/ b0 A4 [ /* dram_init must store complete ramsize in gd->ram_size */: o9 [9 m0 F5 n# g% h& D
gd->ram_size = get_ram_size(+ I0 D+ Y( @0 ? N) Q
(void *)CONFIG_SYS_SDRAM_BASE,: |- V8 K7 ]& V
CONFIG_MAX_RAM_BANK_SIZE);
) |2 J7 J( b: C/ \- o return 0;
1 |4 x c# q. j6 p7 ]2 I; `}
! G$ N5 T/ }2 x, p* A
Q0 h* o& v' O- a- k$ y# A3 ?6 p5 a5 B6 q# T
' L( d) j Z+ G2 I
/ V' T5 ?5 k5 }$ b: I \8 hFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!& @) P: {. M" i) I) \8 e
& F. I- k9 f1 P1 u! R" ~, k
+ E6 v; K0 O4 \6 b _, M3 \( u) ~$ B- w
|
|