|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
1 V- X( w9 X+ F$ [/*7 D* ]8 O: ]+ h5 g/ G
* Check memory range for valid RAM. A simple memory test determines8 e+ X, U# U, W7 h: P
* the actually available RAM size between addresses `base' and$ y w g+ W1 Q5 Z6 }, `
* `base + maxsize'." Q- |) w- s" B+ E' M" `3 e1 O; x
*/
c8 V5 x1 w( j t- r nlong get_ram_size(long *base, long maxsize)
; _! h) \* B: \$ Y{
' `1 e! @( z7 _ volatile long *addr;2 T" [! f0 Y, T: c
long save[32];
, f, d# o( |+ o! E% K. W! c' ?: v! u long cnt;5 j) F! U: R/ b: D( x/ H& s
long val;
, p" L9 n0 C( o2 W5 p; v long size;
1 E1 P) e4 ~! f. F# E+ Y$ o1 N$ W int i = 0;2 }/ g! q1 C; S5 m. @0 y
+ J! c. Z! r, J1 ?, H4 H
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
: h5 k8 c" r, e: F# g- i addr = base + cnt; /* pointer arith! */
3 ]$ Z* ~& C: a/ f% A( T sync ();& N% @ u$ r4 T7 |- R
save[i++] = *addr;4 i, `1 W+ E9 P2 t
sync ();
# ~+ J; O# a8 | N *addr = ~cnt;6 y% g) _& P# s$ E) L3 x
}9 U) M! r6 h/ w3 n
. \' L: l3 O8 j5 v. d: b
addr = base;
x6 f* Q7 K/ i% A0 J- V4 \ sync ();
: F. }0 w0 I! S3 t save = *addr;
# o |; b, d+ g7 S7 r sync ();
* e/ |/ D9 m' O3 c O *addr = 0;
/ Q0 U1 a' t7 l# ?3 h
8 b9 ]% V5 V6 h) l4 f6 m" w1 { sync ();1 S% p2 | \" T# l1 B
if ((val = *addr) != 0) {# b3 j. X# U. _6 j' S* n
/* Restore the original data before leaving the function.
. v6 K' [( ]; D: {: f9 W */! c/ P! U) ^; } M) m3 P
sync ();6 R- `2 R/ X5 x; _/ u
*addr = save;
7 s% D: R. P; y( m& _' g for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
' Z4 h. i* q5 ~- R$ l/ A1 Y# } addr = base + cnt;
& Q6 a1 v% j: _- G2 N sync ();/ J( _5 D- m$ D% a2 x' G
*addr = save[--i];, z! k1 Y# W: ?) c. w, G
}5 T* u. m7 U$ v: D; D( h
return (0);
4 ^. T) x* ^/ w( G! Q5 X& w }! c% a- t9 a2 g$ e+ { ^! }
5 h# G% d4 i. d
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
& ?6 ~! e V8 z0 H addr = base + cnt; /* pointer arith! */
( Q4 [) b" W5 z/ Z: i/ T# r val = *addr;0 x" C% k2 `# C* l2 @* I/ l# u. P
*addr = save[--i];" m( P( y* ?6 U3 D" \( T O
if (val != ~cnt) {
, `- r' e) n6 u1 q size = cnt * sizeof (long);$ v; s" T4 z/ H% l! }( [
/* Restore the original data before leaving the function.
: s/ F; ^6 Q9 v& q. S" N0 V0 E */
' ?9 {' A2 W0 j2 J% M/ Y8 m for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {7 Q, m2 t5 e3 v3 W
addr = base + cnt;9 H$ @- t4 ^# H/ |+ t$ n& h8 z1 b
*addr = save[--i];5 i6 X: G) w5 e
}
' x3 S8 P8 \% q1 @ return (size);
0 [1 ^( T3 }: F6 b$ E. }; r }
! M- e/ E: d. F8 C* f7 O6 i }
7 E- o% f; k* Q2 O% P
e/ x# v! q& O# U3 l5 F. s6 l return (maxsize);
# R+ c+ U1 y5 [! N' Z8 ~& w6 ^}/ {. J- w# u0 S7 X0 _
int dram_init(void)
1 j( o5 f) e$ _& J{
8 J' {# @+ V) B/ u N9 } /* dram_init must store complete ramsize in gd->ram_size */
5 D6 B( L( {) l& \/ b3 \& }% r gd->ram_size = get_ram_size($ A& a/ m5 p" Y
(void *)CONFIG_SYS_SDRAM_BASE,. [' S; i, O1 b2 I5 X
CONFIG_MAX_RAM_BANK_SIZE);* W, N- S- r- `/ h8 k7 J: o& N
return 0;
9 m$ } v# Y' `- X} H$ Z& F; f* U2 O( a
1 M( F J, k' Z( y: Z1 x
0 o( `& x1 {) B5 a9 F+ n s
5 J! O7 P B% @( w$ c
" D' i' V9 b/ E6 C% qFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!, H1 ^0 A2 l. }& S# B9 P6 N
2 O1 H+ L, o1 G( m7 h5 s( }! J7 a0 v/ f, p* ^/ r
" S5 S- u8 _& t9 [) K0 n |
|