|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:' `) L0 S1 f5 K9 X* C9 s! y3 J
/*- G" r! [& i& f, D, S4 ^& S: X9 [
* Check memory range for valid RAM. A simple memory test determines
; X. ^1 ?: f: I; H* V( y- K: `* the actually available RAM size between addresses `base' and
) o( Y4 a, j J* `base + maxsize'.( g- R3 F/ H1 x1 c$ h/ c
*/
7 i. V8 h4 J: r7 ~1 elong get_ram_size(long *base, long maxsize)7 A% c' |. D7 N3 x8 q( K
{
+ {0 y* x0 j d volatile long *addr;" u6 H* r4 x/ N# N
long save[32];; Q8 ]$ @, n8 y1 ~4 j
long cnt;
3 R; |# v" ], [ B, D" C3 D long val;" u3 Z( G! m Q6 O) ^8 [
long size;- {. [5 E' P; p6 u6 T1 ?( h2 ]; `& ]
int i = 0;$ E" P. k/ w Z# z' M% V; I! y
6 N- A# ~* c- y$ h; b3 B' R for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {: O# `; |& n/ M1 t$ {
addr = base + cnt; /* pointer arith! */2 l4 o Z8 N9 ~, x5 C/ L
sync ();9 q' Y- r% v- ], H# T2 q
save[i++] = *addr;# |6 d1 F( x+ C i+ d( B
sync ();
1 ]1 b3 ^' U9 j. x *addr = ~cnt;
5 o' d: A' y; z# ] }
2 Q |8 c/ W2 E- W' q& Q8 Q; @% d L$ G7 W& Z, Y9 U
addr = base;
8 f7 a- P5 U, [7 C sync ();
3 w2 p# q: |$ _' h; X save = *addr;# _6 V( h# {8 ^9 l* W, ]
sync ();
5 u9 Z+ x+ Q r& a' ^2 j *addr = 0;
l. @+ h- d6 P5 c3 F3 Z
# @ }/ n7 L4 Z' M5 F sync ();# S; m# Y0 s! ?; Z2 @
if ((val = *addr) != 0) {
# ]3 i, t7 ~# d* E! n- O /* Restore the original data before leaving the function.0 H9 E4 ?% j$ D9 N4 `8 u4 m. a
*/& a& W! G% s4 _( y6 v2 D$ k
sync ();
' o0 K0 M' u4 s( F1 h* p- X *addr = save;
0 `% s) m: q& ~ S6 ? for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {% B$ K7 }' D- Q) m/ C2 V0 b/ @
addr = base + cnt;/ V* }4 K2 G9 w: A
sync ();
' p& i+ x& r! k4 I- T6 a Y *addr = save[--i];3 e9 z8 X9 F. ]+ q& [
}
7 q# v9 o" d5 t return (0);+ k7 B2 }: f/ c& d* t5 X
}0 z: Q1 H9 ]7 X- q6 w/ ]7 T) O
6 Q8 Q) [* K8 K! Q! ? for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) { J6 }9 I, z: @9 H G& W2 T
addr = base + cnt; /* pointer arith! */
* T: u% \8 u* T+ l- s- t% X2 R! v, [ val = *addr;9 P- v* V3 a) Q* p. G2 V
*addr = save[--i];
' u* y' }- D8 Y; b" f if (val != ~cnt) {
5 \) B7 J( w( ?# }4 E size = cnt * sizeof (long);, r0 ] O1 E8 h- d; q
/* Restore the original data before leaving the function., x) T* U/ [ z4 {; v
*/) J$ L' r. W# |. B* Z
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {; e5 l" A1 S5 n' q6 ^, Q
addr = base + cnt;: e8 d& D6 c W( O$ `' D" \! T
*addr = save[--i];
: T) F6 a9 a& p) X2 C% I! P }
! D; H" V; }/ ~+ T return (size);
5 p8 h; z' B& O: i0 h' |3 X9 e }, B; C* V: m# d. M& v
}; O4 d; I1 ?( ?* D$ f
! {5 C4 H+ U, E3 c* a
return (maxsize);2 @) ~, G \0 E! ^; @$ p1 A0 u
}) ?! O) V' T* y2 U; E8 E
int dram_init(void): f {2 x" A: t# P- K
{9 C' Z) s% l! d& K; C* t7 z: B9 `
/* dram_init must store complete ramsize in gd->ram_size */3 [9 V" q- v/ _. ?$ s. o d. e; ]
gd->ram_size = get_ram_size(3 T4 t7 |" w9 C+ F! o
(void *)CONFIG_SYS_SDRAM_BASE,
& U0 C, y+ L/ c5 j' S. I CONFIG_MAX_RAM_BANK_SIZE);
; J' x% v/ o4 u& z7 G5 Y } return 0;, l/ E- E7 e- [$ g8 G
}1 @& V( U& O! b. Y
7 j8 c! u" @4 F# {$ w2 \+ ~7 Q) O( b1 V
9 z8 K+ D. l# Y6 H7 _ D# k/ o/ g0 \% ^9 A
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!& o* y1 O- w! @, J0 U/ ^
) U4 F: V- L2 @" R. \3 Y
4 D: s0 R- i! S0 w) j7 z
. X/ L/ C; K; q- y0 d9 E |
|