|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:8 E) Z6 V) f2 T, ?
/*; U. |' d5 x; l# L& u
* Check memory range for valid RAM. A simple memory test determines
9 h/ S$ O7 Q( I4 ]5 B4 n* the actually available RAM size between addresses `base' and( M& e& ?" \" L1 M* J' G/ }1 I5 g
* `base + maxsize'.6 C; O" C- Y5 H' N4 M
*/
; ~) M1 Z4 V' t* g; |long get_ram_size(long *base, long maxsize)
2 e% _9 }* o9 g+ R" X3 ]: y V/ |{
0 [% I1 T; m! l/ I# G4 j volatile long *addr;
. ~ s; p' ^5 v0 y long save[32];$ v9 B) A" }3 k c. O
long cnt;# X/ ^6 R; y$ [3 D; O, R
long val;
: _& M2 x2 b7 m+ w; e long size;
( B7 e! ^3 }0 L int i = 0;/ E& r4 C: S: ]6 Y" P- ^$ a. y
1 H7 J; {. m) v/ P8 T E: t for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
9 M* L: r( [* _1 `* H addr = base + cnt; /* pointer arith! */3 h- l3 i+ r4 _
sync ();/ t" G6 M8 r9 V! b6 n0 O
save[i++] = *addr;
: d- x! \! `! }) P% j% ~0 Q# u sync ();
# Q7 }. `+ U$ L& ~5 i *addr = ~cnt;! c! ?( c$ ?6 O/ B
}/ O+ I9 |9 d+ _0 E
5 U e; Q3 j/ Z; m. @$ |# @ addr = base;
$ z0 n$ M0 N: n& I2 j1 t- m sync ();& Q" t6 c6 m/ @" C+ t( v% m
save = *addr;5 ~2 J$ f4 B6 @# N5 ^# L* M; B- n" Z
sync ();
" |+ s9 r3 f% w: I- L4 D8 u6 a' P, E *addr = 0;
8 k% u7 r1 j y3 d7 N$ ~+ B& A2 V; z+ ]2 Z6 x# f
sync ();6 X D3 @: g( B9 {) m6 A+ m2 f
if ((val = *addr) != 0) {
5 r' d" z- P7 e4 F /* Restore the original data before leaving the function.
3 u- p' @7 S! y8 ? */
* v: e; u, L; b. o) ]5 f sync ();2 H2 g2 |7 v: c5 i9 {4 m2 F0 M `
*addr = save;1 w7 S3 E* o& e) u( G
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
) o V& J' K9 ^* T, |" e addr = base + cnt;
N- f+ P' X" y4 s s0 E0 Q8 E sync ();" a G9 V8 L, W2 Z! O
*addr = save[--i];* B/ M( S1 T1 [8 O
}
" J; @1 c. v# M! E% I- c6 V return (0);0 c) b& X J$ G$ x
}
6 j( v! o" j1 w/ E: O& f% {. `" a7 k8 U! x7 N2 Q6 k! ~# e
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
! C4 K1 ~8 d8 h4 N# `0 A5 r* t addr = base + cnt; /* pointer arith! */
, L0 N& s) w& v7 D; E val = *addr;
9 N1 j2 Z0 m- Y( h9 ` *addr = save[--i];( O* n. d" w$ `' h" _
if (val != ~cnt) {) X8 l) r$ \8 m3 g
size = cnt * sizeof (long);
8 r/ P4 u N) C. H: B5 x+ i /* Restore the original data before leaving the function.! S5 x$ C+ \! r( s3 U0 k
*/
0 i8 O4 Q" }7 J! @# e( I for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
9 o( w9 u/ D/ W- r addr = base + cnt;+ M; y* A2 H3 o9 u# z
*addr = save[--i];
9 i; X; P- n* O4 y( f) ~ }- z( ?# ^2 L4 }" L% U* s2 P
return (size);0 g4 ^% Y. u) C; K/ e P
}
. l0 z2 a/ F( L }
! A5 ` j$ k) Y: m- o) C3 Q3 D
6 [- G$ t4 D3 ]8 G return (maxsize);
! X' c' x3 m5 O( x3 j: b9 }8 w& j' A}3 [8 C3 M6 e7 M7 Z
int dram_init(void)2 v' y4 I" l4 Y1 k1 p: [
{
- g$ R3 |* U" z9 `$ w# o. R /* dram_init must store complete ramsize in gd->ram_size */
1 U8 d0 @; K* u7 D* I9 A9 F3 b+ D gd->ram_size = get_ram_size(
3 A4 x9 \2 P& y/ G" ~8 e, @. b (void *)CONFIG_SYS_SDRAM_BASE,2 b. ~8 z# N( r
CONFIG_MAX_RAM_BANK_SIZE);4 Q. B% I) p, [4 O/ Z' W
return 0;, `' O+ t* u2 @" Q
}4 q. o" J0 o5 j4 }# D& {2 ~
5 C0 Y0 K% w( u) l
; ~* F2 l; @, Z4 U
, r4 t$ U; _( v$ ~; M9 R
; k6 C6 b% w) L- i FFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!" d+ R; H9 }/ j* @
# C. {5 I7 O1 C/ l7 e/ O' H* X7 ^$ n/ S& C9 f/ D) f. ~
6 F$ q5 P" J% P a. V' [ |
|