|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
/ K- ^6 v# X ]' Q/*
7 b9 J- ^/ o5 Z" h* Check memory range for valid RAM. A simple memory test determines
* D, A8 p6 @2 Q8 |( G* the actually available RAM size between addresses `base' and
/ x2 R& S( |3 j1 E* n' b* `base + maxsize'.0 b1 _4 [$ m3 O& o5 ]! A- Z
*/1 U" v2 n5 R- Z/ M7 u
long get_ram_size(long *base, long maxsize)
, l, g0 J6 z/ c{
9 w+ s. u4 w E6 C) T: B1 z volatile long *addr;
) b# B% M" R' s* W" x$ ~5 M9 o long save[32];' y& y& x V9 b6 L6 u& g
long cnt;
7 _: E @3 }% [7 |7 P( ~$ K1 E long val;
5 @6 `, _3 Y& @2 m6 n long size;% k6 M( X( O" {; N+ X, t
int i = 0;
& Z: W0 R( J( L) w: _9 N
& h+ o; L+ j! v# c$ A, l for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {0 I l4 h$ I$ r `0 S Q& p
addr = base + cnt; /* pointer arith! */3 k3 O+ q/ F' S
sync ();
* J# k; \0 h9 J- r+ s: a save[i++] = *addr;
& F9 q! N8 F/ K1 C5 u3 n sync ();4 K" Z3 b1 R8 p7 f& e! h7 q
*addr = ~cnt;/ c8 r2 x7 f1 g8 h6 v/ i" E
}
+ n2 N+ W& l" N, Y" }3 ?6 _; B4 S4 V9 y* o" r, t% X
addr = base;; z/ |- g5 w/ C
sync ();
8 R) H' ~- Y1 J- G* p7 C+ [ save = *addr;
9 ^$ V b0 M0 G$ v& ?6 ~6 ~% v, u6 T sync ();
, d; |. \8 j2 S% D *addr = 0;7 u' o: B; C: I* c/ R
( v8 P* M8 ?* g3 Z& E
sync ();: _2 w) j- q" y0 u
if ((val = *addr) != 0) {1 d* `& P' h {/ H6 O3 }
/* Restore the original data before leaving the function.
8 B+ s z3 H9 F0 q" H4 B */
* T$ v o7 u5 l6 s5 z: L t1 B sync ();
6 i* v0 i0 _, D' a *addr = save;
0 _+ P$ p" ?. |9 N for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {- h! B. `: @3 A& s; a8 S
addr = base + cnt;
8 A: V" Z& W8 J8 `5 q" F" g sync ();
" L! Q3 G; v/ X: r$ s( f! Y *addr = save[--i];6 u7 @) ?6 J t
}
8 ~9 }2 w: e$ b return (0);
) D$ r D& g0 Z% k3 S }' L0 v7 m, K: n/ b) d; E
$ p; p9 K1 k) Y, Q$ g/ D for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {- V5 p+ Y% C" h$ i. w
addr = base + cnt; /* pointer arith! */
2 U" I# J+ |! C' P5 T) l6 ]7 z val = *addr;5 y9 y0 D! S6 S8 K8 k' B9 ]
*addr = save[--i];% O- T3 f' x: h3 |. ^; H5 v0 X
if (val != ~cnt) {' c) U# y& V8 T7 C O1 z
size = cnt * sizeof (long);
+ m. g, d: ]9 a* o /* Restore the original data before leaving the function.
* P+ E n! X. c$ o L2 N+ o# I$ ~ */
5 k4 i I+ n. H% v3 Q! ~$ f# E for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {( y1 k0 L- i r- h$ H
addr = base + cnt;2 ~$ x/ J" }$ d. \% U) w
*addr = save[--i];* |9 R! S: g: N9 G& j9 x6 Y
}; b$ q) z3 f- V8 E
return (size);
! n, }9 R* S% R, f }% J# ~. C# h9 l1 v0 e0 ?3 o6 o
}$ d+ H3 A+ V2 R! y: l9 J
. @# v. Z1 k+ R: o0 u5 I9 u
return (maxsize); @' f7 \% Q3 e* {2 f, y
}
" w+ s- X7 c+ S$ H1 s/ ?" Lint dram_init(void)/ S% Q8 Q5 {: ]$ R, r) |- V
{' U5 ~2 ?" V' J% N3 q4 K5 b
/* dram_init must store complete ramsize in gd->ram_size */
( A$ t9 R& u6 V$ i! E6 S gd->ram_size = get_ram_size(
) G8 Z# ^7 a5 z% h (void *)CONFIG_SYS_SDRAM_BASE,& B4 M7 j6 y% w
CONFIG_MAX_RAM_BANK_SIZE);) G$ Q$ ]$ I* E$ Z5 Y9 U
return 0;
3 {$ Y) X$ I" J7 s: y9 j0 Y}
' H& w/ \* h" V1 f3 I' z' Q4 i0 p' s* g Z. U/ K
. o R& l0 v6 E4 `! A1 e2 n
4 y$ _! j$ V( t9 q$ g) E
3 N L' n( C! H3 }
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!0 p2 H2 ^( R. [4 b; S9 [. b
$ x, t4 N; X. ]$ m8 B# \: y# l6 H6 e/ T2 o: W$ r' U
% b4 }" X1 O7 ]- s
|
|