9 E4 f) J! Y& n* a作者: 2532609929 时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下: 1 S! }' w8 g- r- b) y/* Y$ f8 b1 ~; R" ]2 q* Check memory range for valid RAM. A simple memory test determines 7 Y& t( ~$ ?9 }0 y; {) l' Y* the actually available RAM size between addresses `base' and # k; g, l( T+ r/ d, b4 J; s t* `base + maxsize'.& ^! @& s& X1 d$ F
*/ - L% J& b9 I" k I) ?9 Blong get_ram_size(long *base, long maxsize)$ }! q, t$ W' y0 e' l/ U2 N7 C) P
{! j. [4 ~2 d3 o+ U( Y! H# A) `1 D
volatile long *addr;$ ]* t- O, Z* j2 N
long save[32]; , _* ~7 Q2 I- X4 d long cnt;1 M# N) d0 Q p7 k4 M
long val; 0 ?2 F& U. Q" S$ v+ \ long size;) A. ~7 A" z% |) Q) Y& m
int i = 0;' [% \. g8 S, p* j: B
- l% `* b" J7 J7 d( @ for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) { 9 @6 Q% n8 M8 z# @; C addr = base + cnt; /* pointer arith! */ , V+ m, d) A6 K. |* P: V I p sync (); + H; P& K# F3 r' q6 j save[i++] = *addr; _/ X9 T* c- j sync (); 9 r K8 o! V. ?9 L3 C; \ *addr = ~cnt; - L2 U# ^( m8 }9 Q- C8 U } 4 S% o! @- U8 o. g c: k+ b5 G* s/ d( `
addr = base; 2 p+ a0 w0 U3 S. O8 r! _ sync (); # | X4 i9 E: j2 x5 \! p+ ]# H save = *addr;0 v1 l8 o- v( Z6 B% K# r
sync (); 6 W# Y$ j9 R+ K *addr = 0;! o7 c m( ~' w' X
. g' C- A" ?. y/ H, ~" A sync ();# q7 v- z- o' }; g7 J$ {. C+ m
if ((val = *addr) != 0) {% I, K; M! b5 Z# ]* c3 t0 t
/* Restore the original data before leaving the function.+ F8 W }3 l, Q, @4 t
*/ 6 u7 d6 J# ^5 ~. H+ F sync (); # p* d. P7 H# Q0 T *addr = save; % m* @8 N- P+ T for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {8 |" T& M' o# c- ~) h* A
addr = base + cnt; ! A6 |; P3 ]* N* l4 ?, ^ sync ();! r2 o# N0 c, C
*addr = save[--i]; & O+ {; }+ b+ X } + w- H! _. T% ]5 ~ return (0);# M" W7 A2 e& \6 ^! N6 e
} 1 f# P! \1 c" u7 L# a5 e' q( [& R" E4 d* } p" p3 t# i; J
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {! t3 Y3 j7 [% | b" q+ G1 F
addr = base + cnt; /* pointer arith! */+ Y3 }6 Z: _' l. Q j
val = *addr; ! m% Q* ~4 \) J! { D5 [/ d *addr = save[--i]; # B$ k% O9 ]5 Y j# [& L Z if (val != ~cnt) {& P# v6 j0 Z, K/ ?& {/ {
size = cnt * sizeof (long); & K; i# K: u0 O, n _1 W8 T /* Restore the original data before leaving the function.0 c# q! D0 f) y3 Y. h* c+ m
*/ $ x, F# T; V# J for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {4 [1 N# M5 R) H+ K7 w; J
addr = base + cnt;- C( x3 [. Q/ j8 X
*addr = save[--i]; % p1 T8 ?; h8 d( w } # R& c4 w, I6 u1 { X, T0 Q1 q return (size); 7 P7 L. y9 q" j# Y0 {) e } & {- j+ [0 }% u- P } 0 {8 H/ z% z2 \2 r& h1 B/ l/ B3 A2 T, i ~/ }/ o: r
return (maxsize);4 x t2 k( r. v' S2 i
} ; `3 q7 c; C4 f! g& I5 _2 }int dram_init(void)/ ~" P1 y% y1 W6 K
{ ! R1 k \) p1 q4 } /* dram_init must store complete ramsize in gd->ram_size */, ~; }1 f& u, x9 j; b/ W
gd->ram_size = get_ram_size( u, g) c0 |# H, O (void *)CONFIG_SYS_SDRAM_BASE,4 m7 o5 l( O: {4 z
CONFIG_MAX_RAM_BANK_SIZE); ) _: i1 @- L3 @- v return 0; 6 ^5 r0 O3 l3 V# e% U} " O" n$ @- z$ J0 \" @: n: R+ ^1 P9 I% S$ j+ V5 z
/ R f/ M0 u9 y" X % F G# C0 s7 S8 T1 v+ J( u. [' Q 5 H' r7 Q v8 ?/ F( T3 }FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助! " J) r1 n7 P* l+ }7 } x) q) X' @9 a2 }9 @- g# N; b