|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:7 \9 m" Y" J, @
/*5 q8 {3 N$ P# F3 F' t
* Check memory range for valid RAM. A simple memory test determines
* p# E8 q3 s) q; Y- T* the actually available RAM size between addresses `base' and
9 Z' S0 X" `8 {4 R- c* T( V/ J- C( e* `base + maxsize'.: S5 h& o( g, B
*/$ E7 u3 H2 \( C4 V4 E1 F: w
long get_ram_size(long *base, long maxsize)
3 r3 r) q8 M- ?- L* Q{( j* a: ^3 G* | r' i! ~4 t
volatile long *addr;
! Z5 u( l* B8 W/ N7 J U6 K4 Z) Z! e long save[32];
& E9 f( D3 V7 A {3 @ long cnt;1 S+ _; _! b& B% L/ Y
long val;+ V- N4 g7 j( ~" q4 l) r$ l
long size;
s6 t. t( q+ i( [; D int i = 0;
$ C7 I$ F+ \3 @. H
7 n8 t- L- M4 s for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) { g4 _ ~! P- t+ |$ y8 I
addr = base + cnt; /* pointer arith! */3 h5 }0 y/ M- i- v% w! Q
sync ();0 T ]) H; i1 Y0 L' Z3 U
save[i++] = *addr;
8 S- o& L! M$ | sync ();" H3 X4 w1 d4 W/ g- Q
*addr = ~cnt;. u. b5 X; B; }2 J! r
}
# x9 d5 T4 W4 K4 o0 `" F) Q$ Q1 b) i( i/ M; ?
addr = base;) q- t7 [ p6 L+ `, g6 {1 z$ N1 \$ _! E
sync ();
9 H' k: h" |% l C6 s/ M/ ~ N save = *addr;
5 d8 _4 N1 V: b& P& L5 r- i% _5 a sync ();
4 i" _# H& h6 v *addr = 0;( Y4 n5 q0 R- ?) }5 m @
+ H" T0 p- H3 p2 l; k
sync ();) H% k. h& o# P) ]. E' |7 P0 f
if ((val = *addr) != 0) {
0 ]( J. {2 c9 h' o. c /* Restore the original data before leaving the function.
. S' z1 N1 q: ?7 X0 {7 A- o2 s+ R, f+ _ */4 m! T& }, b# e2 r: |
sync (); e) q2 B% t+ r9 \2 @
*addr = save;& a: V% r$ E6 t8 I' W; }, `3 X
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
; U- U! D( Y0 M addr = base + cnt;9 Q6 t, n( `5 C
sync ();
7 {3 n2 s S4 W1 u; [$ b *addr = save[--i];3 u3 h/ l. O v3 u2 X/ `
} q! I# ?5 K# t4 B( K' G& K& h
return (0);; E/ O0 b! U, U( @# Z6 q
}2 }- V1 @# p# b" i9 s7 k
+ c2 I. |; Z% C# Y3 ]+ o5 {. B% Q
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
* u; D0 ]( O7 A& i7 E( l addr = base + cnt; /* pointer arith! */, J* J$ l/ P. ?& h# p/ h
val = *addr;' d& h1 i0 {3 ]
*addr = save[--i];
7 U' l! e3 ] k1 u4 c. {1 B6 B+ m8 D if (val != ~cnt) {$ J! L. k$ G* d X7 e% V
size = cnt * sizeof (long);
7 }8 C# k4 z# N; n9 Z1 _! B* Q /* Restore the original data before leaving the function.
_& H/ `4 u( J6 g8 L' p: d5 B* K */
9 n! `8 Z7 w: W7 B) k- H for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {- f! W% E: w+ @% E' B; q
addr = base + cnt;
; W: Z( k' B, T *addr = save[--i];
4 c2 k2 a0 P' s) x) u* T; f6 x }
9 [1 ?. u4 _% L3 W! z/ i7 _ return (size);
. u$ _6 h5 s& Y }
6 A8 r+ o) u+ m }$ K8 B9 I* Y f8 i- S1 W% [( ?, v' C' f
" J/ \! l3 ~: y return (maxsize);6 p. L' n" K. }4 U
}
$ n5 f2 B, X3 U2 ]4 @int dram_init(void)8 x( B# e$ ^& o, l8 x6 r5 Q
{ b" M6 \/ i( b+ ^2 G# l7 Q: E
/* dram_init must store complete ramsize in gd->ram_size */: {5 E: i& M- B+ b
gd->ram_size = get_ram_size(
0 X" n6 h3 F V ^) T (void *)CONFIG_SYS_SDRAM_BASE,- `) f( A- {/ T% ]6 |1 i
CONFIG_MAX_RAM_BANK_SIZE);
3 m1 H( {3 r# L4 ] y+ ` return 0;- o5 L5 J! n- o7 c; g
}
% a* f' z/ M3 I9 C, K3 K& ~
" g1 |8 v2 |) w+ Z# b- R+ P) ~# `, P/ E; ~3 k' s9 z
" A6 q; A0 g5 V% s. _( x# e
% o/ s( @; ^6 yFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
1 H2 S$ _! E8 R# U( i6 O: p5 Y8 H) z& a) z* o* h
$ |$ D. M; u! Y3 W* p. _, W( r7 B" ?% G$ E
|
|