|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
8 v0 R6 C3 S- P4 z+ e/*
% \ l1 ?/ _2 [7 c* Check memory range for valid RAM. A simple memory test determines( a" [' u ?; ^5 d: Q" ?9 M0 l
* the actually available RAM size between addresses `base' and& _: |( q9 r0 i. M5 ]6 |
* `base + maxsize'.
# e2 [% k( o4 h u*/
' f8 O d5 `( N9 Olong get_ram_size(long *base, long maxsize)
$ l$ X; B! f, b5 g{9 v( v* D- X7 n2 T9 u) @1 m
volatile long *addr;
- [" W1 d# o' R1 ^# N long save[32];
& i: E: z3 z( G2 T long cnt;' h, k. A" Q' ?5 ~6 ^
long val;
% ?& R8 U2 s9 C" e9 P% b' C long size;7 _, @% S9 q* E% n( w1 j$ k F
int i = 0;7 f$ Q, t, u2 f+ R- {
1 ]0 D, Z Y8 d4 W6 \ for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
4 N, ]4 T4 p) c9 T) l7 {4 \5 c addr = base + cnt; /* pointer arith! */
+ Z. n# ^2 r9 M/ j5 ^ sync ();
! |8 U& s3 Z- v save[i++] = *addr;! c4 o$ N% j! ^, k
sync ();$ |0 c/ ]& t i6 d
*addr = ~cnt;
7 O* u' `, D! k) y }2 }$ N& i( B( t& j. l8 R+ V. x
. m0 I- U' n" E addr = base;5 b4 q- K& r/ N) l8 `
sync ();- b! D- G& \! y+ g2 a- O
save = *addr;
0 N' [/ s" ~0 D! _% a( Q7 Q sync ();
- P+ D; D8 t. a, @/ `! j2 a *addr = 0;3 o4 ] n! B. t
5 j" U7 ~% I9 |6 Z sync ();: ^8 o5 R5 u, o2 ]0 X! V ], q
if ((val = *addr) != 0) {
5 t' ^- |9 q' W4 r/ T$ z /* Restore the original data before leaving the function.) G e2 h7 ^3 _2 `, W( |/ Y
*/0 F: C, G( e" W) ?- h
sync ();7 I& H* y0 u8 [' h# t
*addr = save;
: _% A! ?5 n7 u! ^5 F! x for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {; m5 e1 H' P _$ d
addr = base + cnt;& \1 h4 X- f# f7 f
sync ();
@( h$ A& ~; U8 c4 f! ~4 a3 t *addr = save[--i];# U9 {; E$ g8 R6 S; k
}+ u- M+ h, ~) t( e) n ~6 n
return (0);, J Q6 K. L9 [; H2 Y8 K
}
5 |; P6 [3 q6 y' _7 J. Z
7 j+ B( P" L7 L& I& D$ `; B for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
8 V& @$ L4 j4 @ addr = base + cnt; /* pointer arith! */
/ P3 l/ q2 s: ?0 R$ W' N: |' \! Q9 F- i val = *addr;
/ h- r* R, O. R0 O1 M6 t/ f *addr = save[--i];
9 C6 t* r; B6 @' p# G; n" k if (val != ~cnt) {
4 J( l, o; {8 w6 x size = cnt * sizeof (long);
|" K0 B- Z/ z. j7 n /* Restore the original data before leaving the function.& r, X, C5 G# l: N4 E
*/
% s& P' a( R, J* O3 P for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {9 I" Q; m( ?* n* ?* Q
addr = base + cnt;# x+ |0 f, j/ G9 R4 F5 O; s
*addr = save[--i];1 o, m* `1 u6 ~ u" G
}
8 I! D, e! h# o3 c return (size);
+ Z/ f$ H% @+ L4 {0 h/ X( i }4 x6 @7 P# R2 `% z* o
}" v8 W* Q* ?' r7 b0 V6 {
7 G2 X* z% _* a# C return (maxsize);3 a% ^8 @. \& V! v" F( o$ A
}
; O$ h+ H# j/ `# D) sint dram_init(void)- m7 r# c% S+ m# h. i
{
e+ S8 U; m1 i /* dram_init must store complete ramsize in gd->ram_size */) E( ^$ `- Z2 Y$ [6 d6 h' [
gd->ram_size = get_ram_size(
& m" o. A2 ~2 F0 W& y* A (void *)CONFIG_SYS_SDRAM_BASE,' I0 ]7 b" _* P K/ ^5 K. @8 Q9 Z
CONFIG_MAX_RAM_BANK_SIZE);
" p) @5 }# V8 K/ [! B- |* X; R return 0;
/ K% p& j! B5 u1 O% V, G: |1 T}$ x( c( r$ H f- j$ N. w
4 P0 P7 @' H3 F, P" \6 _+ X2 g K! G/ f$ `: V- |
$ D H8 Y* U0 F/ I7 e" Z0 V, s1 g) v$ E y
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!5 V, p2 U' }: ?9 U
3 A$ ^" u' E s9 w; ^; U, U0 K- h* M
0 C; Q& b0 |& `" P& t" w2 K) I! T
! b9 X/ {% {. {7 q& l p+ ]6 v |
|