|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
1 l0 m! O/ B( X4 G$ U6 i3 R5 {/*
6 E9 y2 j7 G s* Check memory range for valid RAM. A simple memory test determines
- n9 A& D! K1 m1 e9 H* the actually available RAM size between addresses `base' and/ N1 |5 z' h% w5 t' {
* `base + maxsize'.
& d: M# ~& g( f$ r. T*/
6 R6 ~; C v, Blong get_ram_size(long *base, long maxsize)" N+ f' t8 S( h
{
4 R* ^+ V3 A$ s" Y- d: T2 F; B volatile long *addr;
/ S6 |9 P: j$ q. D6 Q I! M long save[32];
7 \) N& p/ T( F6 O9 r" d( c long cnt;$ u) E! K" @1 Z* {3 V+ W
long val;% u( e. m. W- @, H% _( C1 _
long size;
. ^! j1 y) S1 q* t+ t/ ^" y int i = 0;- G! ]- z. N2 V: m
3 a2 Z# x9 Q* K. N$ } for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
; f, m- f6 z7 e" Y2 G, X addr = base + cnt; /* pointer arith! */) X3 y3 o: @% C
sync ();" z, n) |& k- g+ [! q
save[i++] = *addr;& B5 ]2 O& B# l) o: w s1 {( ]+ v
sync ();' B) ~& t6 o5 D; r+ d- l. ^1 @. x
*addr = ~cnt;& `( c0 k2 L9 z G# J
}
9 I0 O' A5 G: i5 M4 b! D# F0 k% L/ v4 J3 }9 P F# D: x
addr = base;- [' ? H( V7 Q0 `# }
sync ();
: c5 e2 z, V1 t6 y" O3 b save = *addr;; W9 Q4 ]7 U4 a( Q: [
sync ();
1 G3 l2 q+ O+ _0 h" ] *addr = 0;2 p* c# D/ N2 t; f( b1 W3 \+ S
2 _% U+ w: V9 b7 W2 U# j* W sync ();- Q+ A5 E( U. O* Q9 N7 ]' p( @
if ((val = *addr) != 0) {: ?* ~5 L7 t' D4 }4 D& y* g
/* Restore the original data before leaving the function.5 B5 e! o; e0 @1 h, B
*/
8 a4 }% R \/ f0 Y$ h sync ();' N1 c7 F9 }( c; x( g2 E
*addr = save;
9 _/ n4 ~7 T7 v5 ^ for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {0 V) S# X; j8 f) l0 Z
addr = base + cnt;
0 j, s& P5 T7 X% y, ^ q g sync ();, b: ~6 S6 ]. S5 {
*addr = save[--i];, A1 p% Z7 y# ^* V1 a6 l$ v& j3 X
}
0 m7 p3 Q I( h' v2 _/ D3 ~2 n3 w" W& P return (0);
8 g$ A4 V8 R, P( e& N }
7 i( n# _: p( n, |9 m- \6 Q$ [% v! [$ r8 V2 M' j
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {$ ^6 z" @2 U% a7 v
addr = base + cnt; /* pointer arith! */
" r: |' ` A3 ^% {$ A4 d7 } ? val = *addr;8 x, K3 `7 r7 T3 I6 k# ~& p8 V
*addr = save[--i];
0 H# q: p& j8 |5 X k+ M* w if (val != ~cnt) {
' |! F4 `/ g: ^6 L: y/ Y2 U size = cnt * sizeof (long);1 X* M: I2 G8 q3 h$ G
/* Restore the original data before leaving the function.
% N0 T& f' S; H; q */
0 N1 b0 L, X5 q' |. y0 F$ @ for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {# } P/ M# w/ g+ T
addr = base + cnt;1 Q6 P) P) }$ i6 ?5 j
*addr = save[--i];' v( o. A; H! }( S$ V8 B% q% {
}
: {% Q, n v2 s return (size);
% L8 p1 r D6 D( @/ o }, B( P8 B* _/ y2 ~9 f8 K& O u
}
A* q& i0 U5 H. S1 J6 T ~ [5 I8 Z4 T3 n" t$ n
return (maxsize);9 i+ _. w" g' ?6 m# X4 v2 a* D
}/ C' W8 t' J( O# q; o$ ?
int dram_init(void)
8 m9 o! h( o" B- z! J, f{
5 d1 v, l; ~; W4 I! k r /* dram_init must store complete ramsize in gd->ram_size */
- D) m8 S0 K5 i& V" R! |9 G' G gd->ram_size = get_ram_size(
+ Y2 a9 N) L6 H: r (void *)CONFIG_SYS_SDRAM_BASE,# N8 U* K$ b, }( x0 c& P
CONFIG_MAX_RAM_BANK_SIZE);" k( ?% g; {1 o* c2 [1 |
return 0;. i" A3 x3 }0 V9 y5 Y% \. {
} [- }3 D Q) ?- v2 a
8 h z8 M' J. Y/ j
& A( I* f0 [ {# F- ~6 g& t
7 | T4 Q4 u0 `& @* x
" ?) u7 x F |# A5 cFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!" X) ]; R0 ^" F/ n2 m; M
- E3 ?& ^) t/ _/ k/ j y% V) r
" ]1 z/ u/ o0 X. K& m) B' Q$ h6 `) g% G0 M; |
|
|