|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:0 p& y T/ q/ b& I; B# X3 x
/*
% }! O4 n0 v$ I! V& R8 k+ O$ ]* Check memory range for valid RAM. A simple memory test determines* D) W: o% A4 W7 \( A |- f/ V
* the actually available RAM size between addresses `base' and8 T+ A/ b6 D2 T+ \& O t
* `base + maxsize'.9 X* W6 o! j& m8 ?# ^
*/# F( ?* W% C6 v+ a
long get_ram_size(long *base, long maxsize)
! _& V1 O$ ?# T/ L) w{* P( a T u4 s) j' s' m( c
volatile long *addr;
0 E3 H9 d( ?9 x+ C2 g# l) W. D2 E long save[32];
0 l$ w2 g2 ?! b3 K& M, T5 b long cnt;+ |% d) {" l/ M9 \/ d
long val;" ]9 o+ s( e" Z! n
long size;
! w/ B. y. ?) ?0 F/ U0 O2 O int i = 0;
3 T5 r" I+ Y2 L2 F) j M$ i8 a
5 g5 w4 Q" ]- m$ v3 x b( q for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
$ v; c( c x( c" k addr = base + cnt; /* pointer arith! */
& c. z& F7 e8 o5 h0 z$ Q$ s9 C sync ();
1 n5 c: o! y$ _3 p/ l save[i++] = *addr;
7 q i- k' ?2 h9 p- s sync ();/ O G. U2 ?; f5 P* \& s
*addr = ~cnt;
' Z4 k# N( e3 e* o, C4 F4 V }
8 c- W0 }1 x( ~! ]3 X+ W/ d* Y' ?2 a* C `* q& X
addr = base;
( V5 a. y3 M& K/ x( m sync ();
( |+ c- p1 {2 E) t save = *addr;
# W* \4 l2 M' `1 l3 \ sync ();2 k* _' h( h' F" Y. M% b
*addr = 0;
4 W; j5 j% ~8 E+ o+ O% B* x4 @. b! J. j
sync ();
7 O$ Y7 [- p" r9 R; Y- j2 N if ((val = *addr) != 0) {
& V6 ^; \5 d. n+ Z /* Restore the original data before leaving the function.
; s2 g3 d2 c* f# T8 v8 h6 s */! n7 ]* ]( O+ k8 @# C& M" d' G4 q
sync ();# f' a" U3 R: ?) A: K& k
*addr = save;( }/ y6 N+ P5 w8 o4 o
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {' C: l) @& f! v, L6 J3 e
addr = base + cnt;! {1 X" ^) @" I! A+ X' ^
sync ();+ D0 d" `& t- A
*addr = save[--i];
( I( G) v; V/ t! T1 G }* ?- Q$ L- u: ^' t! G6 a$ b0 R: S
return (0);0 k7 T P6 y2 p0 r
}
8 u) |2 p7 ]5 W2 W5 m9 `/ M, N* I8 S( F/ z$ D6 Y
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {- p N( J& ^5 q7 Z9 f2 L% q+ v8 g
addr = base + cnt; /* pointer arith! */
0 X( n0 o: W7 S& {& q; U val = *addr;
/ |* k% {) n% _7 L, q" p *addr = save[--i];
4 u7 p/ x& t5 o- V* J if (val != ~cnt) {, R6 y' ^& j4 k0 d; _
size = cnt * sizeof (long);# J2 F2 E) o2 Q/ _
/* Restore the original data before leaving the function.2 J h& n: @: _+ x! j
*/- ~6 J- H3 B- v
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {( k8 x1 S6 p( k0 ?* z. v* G
addr = base + cnt;
# k" n7 G0 O9 D* z9 c }& i, [ *addr = save[--i];
) w0 L6 N. a- x% |0 q8 ?# O }
) B3 P3 |" ] {' g return (size);
; t4 L. d+ `5 P- @( Y }
8 M+ | ~$ t) f: `1 s& F0 i }! X5 o& o/ g6 ~1 v5 b
. }7 G7 ~0 Y0 L( { return (maxsize);
, Q0 z' y \/ y6 T}: f: X7 Z" l# x* q: C
int dram_init(void)& _3 Z* D* F- P
{
) E( U4 x$ J" G7 ]: [ /* dram_init must store complete ramsize in gd->ram_size */
+ \, N" q$ {5 }9 T3 s gd->ram_size = get_ram_size(
: z# p0 w" }6 p& | (void *)CONFIG_SYS_SDRAM_BASE,
, Y# F" ]1 M; K" ?3 O8 G CONFIG_MAX_RAM_BANK_SIZE);2 b1 y, r* S) J$ {3 @/ z4 ~
return 0;
9 q, |3 k3 [0 }3 S0 h* X}5 U7 B3 g( O7 a* `4 P
7 a- F8 o3 t) R" h
% I5 \0 H5 I" L. I* n- S3 p$ e" m3 R6 L
0 H' d3 [% q; r6 dFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
" t4 q, V$ _& c9 C: P+ q) r+ g' [! q: z6 o
. F- I( ], V) Y. A
6 A0 l: L2 D" ?5 E( o |
|