|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
9 b9 B: ~; L" L/*" o( S6 F" r/ f4 z8 d
* Check memory range for valid RAM. A simple memory test determines
5 x6 @: o# y( G# N a& c9 s* the actually available RAM size between addresses `base' and# Y8 N: ~4 c' f
* `base + maxsize'.
( r) S; p: F% y# l/ c W*/" j7 j9 l7 ~5 t6 T* S$ t% @: U
long get_ram_size(long *base, long maxsize)
* }1 l7 g, q8 b/ O, e4 E4 O% S$ W{
' ~& u: N# }" N4 ^* F! F+ P0 S; T volatile long *addr;
7 X- t7 h/ q. w# S" m" L long save[32];% v- I6 i6 u1 i/ M! i
long cnt;
- y H- T7 ]7 }' V long val;: w+ }; R7 Q* M9 c1 g
long size;
* X( b! P& A$ {5 K int i = 0;
8 f4 y9 O/ D( i1 n0 q8 D: \9 C( V$ d" S
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
- S( O# G" z7 M1 k& \6 l addr = base + cnt; /* pointer arith! */5 h: u# a$ j6 _* T! U& W
sync ();+ `- U# H+ N/ D: E3 w: G% d
save[i++] = *addr;. h! L2 l3 p; ?* _4 j8 r0 O2 p
sync ();
8 Y l/ m+ p5 Z *addr = ~cnt;
9 E0 u; r- f7 ^$ q; n$ X8 t# z" u6 | }
7 {/ I: n# Q: i/ Y3 r
% ]4 E! J% N0 M; n7 D; n addr = base;4 |/ `0 N& v1 g+ I5 B2 r
sync ();* n0 `9 m5 L5 L/ e
save = *addr;- T# U( z. i% N0 [1 v) `/ L
sync ();
4 C. S8 {2 J* ^+ P. w8 B: _ *addr = 0;0 x9 n$ P! _% N& |$ y( x* t
. U0 J4 f3 M$ F- i- n. @ N sync ();, K4 _3 V3 {4 B4 c* H
if ((val = *addr) != 0) {% G1 C4 J& ?/ `& h, w2 X) Q
/* Restore the original data before leaving the function.
, h$ v/ L2 c; w3 T& { */8 E1 u4 V; A7 A7 h( U& w0 w9 e8 X w
sync ();1 {) C! [' l6 M; f: X& ~& X$ t
*addr = save;5 ~2 d8 b% L' X- L! L3 f! E/ N8 G
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {4 p& ~6 w* ^) I% @6 Y1 Q, U9 s
addr = base + cnt;
8 z, n5 z; P% G& u" ]9 ?4 S; U sync ();$ u3 I/ B6 r$ v L+ A! r
*addr = save[--i];, [/ u: c7 a! ?
}6 J7 ~% w$ L5 A( z3 |
return (0);+ o$ z$ w: [# L
}
+ L/ b- r9 K7 f% |( p; G: Y+ q$ K3 M' T: K! Q4 C
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
! m' z" D7 v- n6 J2 H C. v addr = base + cnt; /* pointer arith! */
. S. T3 N+ I; D5 H val = *addr;5 o$ I {8 f0 V3 o! A* X* a
*addr = save[--i];
5 K3 b, A: Y; X x if (val != ~cnt) {3 G* g: r7 ~8 s
size = cnt * sizeof (long);
1 P( d9 P) @* t# O- c /* Restore the original data before leaving the function.% C' L9 a: W, j
*/
. C. h8 k$ q8 n2 E" W; o for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
) k# x4 d& B, S; ^/ L" B9 ? addr = base + cnt;
j' q4 S1 }8 y9 i/ Z% Z *addr = save[--i];/ H! K! X0 j$ A% D
}
2 \5 T( v; W5 _! j4 t return (size);
0 e! c* s3 a$ }5 t9 K9 W }
" E0 X2 K' c. e/ h5 y }
) ]8 w g! r* \3 x; C/ q, c' D4 q- C2 ~$ T
return (maxsize);9 E! w& C" L# v2 n2 _2 D8 y* R
}+ C( W( P2 T) j0 N8 f: T$ L3 a
int dram_init(void)
/ B" @7 Q' Y! A* l! d{
( f) ?/ O6 k6 x% i, V /* dram_init must store complete ramsize in gd->ram_size */
) j, X6 ?2 `; D2 P gd->ram_size = get_ram_size(1 W- D3 C" i" N( d1 F2 I$ J6 E; ]
(void *)CONFIG_SYS_SDRAM_BASE,% e- T# e7 Y S: a7 n
CONFIG_MAX_RAM_BANK_SIZE);
/ e l; _+ v- X return 0;% J$ S& S# u/ H B! m5 Q9 w
}6 Y0 o; T) _8 X; S, a
4 x5 z& n, u, g6 C$ M/ q
' Z7 @ N: e3 D, h; ], `- f, ^! t) q' t
* f# F+ a5 [9 h% U2 l1 P+ C
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!( u8 |5 r& t# e5 y9 T
8 M( d0 }+ z3 l+ e; v$ e/ }& \+ Y. E8 \8 ^. `) N: I: Z
7 r' B: E$ v1 c4 ~* f# K4 `
|
|