|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:" \/ {; q6 u9 h: C4 B. a' X
/*+ t, w1 Y# t5 ?' }& r
* Check memory range for valid RAM. A simple memory test determines4 K$ {* Z6 {1 ~$ ?/ Q8 ]
* the actually available RAM size between addresses `base' and1 S9 A4 f* j$ z& x: z
* `base + maxsize'.
! d' L9 L! v6 v3 x*/8 l: }- k4 { v5 D# m' R+ l+ S0 e+ V
long get_ram_size(long *base, long maxsize)
; d* w1 ?# L, C1 G0 B: b{$ N" D" b8 C \- J& ]
volatile long *addr;* ?/ a0 }7 ]4 V- a6 K9 [& g
long save[32];2 _! n! q1 O8 K0 y$ n; ?' k4 q
long cnt;7 H- j( P2 o9 e' a; ^$ m" p
long val;; w, p/ x% l7 n8 {' V9 ~
long size;
5 T" u5 x' }' y0 ? int i = 0;
2 @/ q$ R( ?- L o2 Q* A$ D0 @( E* l/ F) n$ ?8 p, s
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {4 r3 ^ r6 |1 x
addr = base + cnt; /* pointer arith! */
: c$ l1 Z1 w* ]9 ?: x9 E! a* f sync ();9 \7 p: z8 }* N1 d
save[i++] = *addr;9 o! n, H/ {! `+ ^, b
sync ();
) a3 [& [7 P/ g9 P+ [: t& e *addr = ~cnt;+ R& j1 E5 C: D% D+ @
}0 C6 L! L5 R5 z4 i# l& m" g
( ]( C+ V, r8 s2 d
addr = base;$ S8 B% T$ h j' w6 h
sync ();
0 [) A) c$ \1 @5 h5 @1 I save = *addr;% G: x" [4 n) l& C) M& V
sync ();- u+ ~# T R9 o% `; s& _. z' g
*addr = 0;! N) \/ z" b F4 }- c8 I
' n/ N( }$ I+ ^; T A sync ();& b3 g0 a; C, m0 P
if ((val = *addr) != 0) {& s; d! T8 O5 g! Q5 C
/* Restore the original data before leaving the function.) d. z: y3 l+ k( S7 o/ K
*/
( T4 Y6 G% H' [/ w! A. {2 E sync ();- G% R" r; u/ G
*addr = save;
" c7 W; Y. I0 C8 z5 X for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
: v8 d, r! _' a! g" ? addr = base + cnt;$ Z0 I! \0 R9 ]7 p* R6 [
sync ();% S- o) G) e1 A* D* C4 y
*addr = save[--i];: T9 b7 O! ?$ f' T! t
}( ?' `) F/ ~: L7 Q8 [
return (0);
P) V. E) x2 p }4 m! o4 z* N- b1 r6 [: ^1 e
2 }' t9 d- M! @5 m6 W, ~ for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
9 \- }3 K+ o! [" h% {. j addr = base + cnt; /* pointer arith! */+ D) \7 H9 _: q1 L5 n+ d
val = *addr;
$ ]9 G+ Z0 b- W6 C *addr = save[--i];* z+ ?* d& o- {, R* r
if (val != ~cnt) {
4 J+ P% o H4 w9 H& \ size = cnt * sizeof (long);! A8 V ?8 W8 n$ A
/* Restore the original data before leaving the function.
/ P" \9 b1 F# V0 g, X: Z- e" _ */5 r6 D5 P( s6 D( }+ A5 W2 T& |- T5 l
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
: c+ B( _# w- h, K3 r addr = base + cnt;' p) h8 t8 A1 ^2 U) R9 l" z
*addr = save[--i];9 m# l. s3 }8 {8 x' C# c) t0 i
}
+ ^4 Z# O! _) O' _* d3 D return (size);
`# L4 ?" o7 g4 R }
8 m# b! ^3 R# T/ ` }+ L8 T9 a" a* h! j6 P
: j& v1 u& l! C/ B4 Y4 I
return (maxsize);
0 ~+ ~6 u( m& M% x3 y& }+ }}' j* ^ W B7 U7 {' r1 `4 ? \: T
int dram_init(void)
0 K, o) O3 a! T( d, w, k{' t% @! w3 _0 V; d0 H
/* dram_init must store complete ramsize in gd->ram_size */
4 G0 |/ S& b" O+ q$ R gd->ram_size = get_ram_size() p G3 _2 K% @; _0 _1 p* l
(void *)CONFIG_SYS_SDRAM_BASE,) D2 a. z. _- i1 j: w, w, H# d
CONFIG_MAX_RAM_BANK_SIZE);$ l3 d. Y1 e& L! Y# q
return 0;
) L. A7 M! t) U$ j4 H3 T}
+ L( I/ ]" X6 G3 b2 R* X) r- h: L; t) d8 n- K
! b0 Q! J2 k2 a0 f: z* x
4 d# P" u4 {3 G( n9 {3 G6 w& Y2 m
% W+ b8 B9 k4 r' K& e/ vFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
9 [5 m- j/ m9 v" }) Q7 M2 b& N& j6 \' k& o( L1 z* r
, R+ ^! g! U! C. M L; l9 N& Z
! S2 a8 h; {* K6 l9 o, b! {1 B |
|