|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
; T6 s- L0 t4 z& D6 l- `/** H4 v. }! L2 H( Z7 d
* Check memory range for valid RAM. A simple memory test determines' H: M5 k+ A1 D0 D* G6 @
* the actually available RAM size between addresses `base' and
, V9 P4 n4 ~4 e9 ^/ c: M) a/ h* `base + maxsize'." F) W V5 K% x
*/1 n8 c2 D9 @! y" n, l6 ^
long get_ram_size(long *base, long maxsize)
+ x) Y( g. i: s1 c0 _2 W. A{" [& f# X c$ y0 Z h6 d3 w
volatile long *addr;7 {7 W! R+ b: H& e
long save[32]; o- w7 u4 A4 J- c- o
long cnt;6 T3 g% O+ B2 B* r0 ~* N' y: W+ o
long val;: ?4 [# B; ?; _" M& f# \0 q* N
long size;
4 `& H7 _5 C9 R% Q% u- Z6 ?+ I int i = 0;3 K4 U8 r/ F5 f q* q4 n0 B7 q+ v
( A9 g8 q9 n( b3 [' e for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {5 X4 `' s6 C9 m7 O
addr = base + cnt; /* pointer arith! */
! v1 W% F. m ?) \* J$ ~$ | sync ();
9 ?* E. d' H) z% f* A7 V$ ? save[i++] = *addr;1 W! K3 c- u* P, v; A# e
sync ();, R$ M( t+ A. n
*addr = ~cnt;
3 R8 U, u9 T, z. F7 a }6 @8 ]0 t; t: `
A: v+ a1 s5 L) I0 r3 j addr = base;
4 t4 L0 L! {& A l sync ();
0 R" X" S0 x7 Q save = *addr;
( l8 S$ v7 b2 A3 I$ @ z' {0 C* p sync ();
' ?% s% l; T: H- b' K *addr = 0;* }# G& k9 k3 N
. d0 c) \5 [4 T; u* h& k& Q
sync ();/ E$ L8 r* M8 P/ o- v8 T+ ~
if ((val = *addr) != 0) {
% x' I0 X/ D5 \: {! U3 h /* Restore the original data before leaving the function.) p; ]1 M2 K& ]1 g5 K
*/) Y1 f: ]' v3 ]: F0 ?) ^5 A
sync ();
) r4 Y. Z: w( M0 G+ O: X7 F *addr = save;; x4 [" ~8 D& D2 s3 D6 C' _
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {5 r0 i! A0 z; f. a9 r( j O, _
addr = base + cnt;
3 I8 J; R) V8 v* P1 H sync ();/ }) `: G; u$ W3 p
*addr = save[--i];
- d3 l: ?( ~( P \7 i }
: e6 L: r: a$ |5 ^2 D @# Z% o8 @ return (0);% v8 J: M% U7 t: L5 ]
}
5 v9 b" H- F1 ?8 [& F3 n' E5 ]6 P+ ~& y l
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
- o0 ~0 Q9 t+ ?5 O+ @ addr = base + cnt; /* pointer arith! */
- v3 k- M" I% g: f; X& ? val = *addr;1 l( D: D$ i" W
*addr = save[--i];2 f) z1 K# x8 ~+ s7 U' @
if (val != ~cnt) {: D; z" Z$ G% T2 N: ~
size = cnt * sizeof (long);
5 k& o" V& [* ^% w% E /* Restore the original data before leaving the function.6 @+ j! J f% H. E$ _: \
*/
1 O! e3 N& b+ \ for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {. a6 A; @) r6 G3 \1 p
addr = base + cnt;
* u: s0 I3 Q6 I$ }. C *addr = save[--i];
/ P; {1 r% }. j* s4 p+ p }
6 s8 Q f) O4 k* g4 z return (size);
* T. V+ \7 l( y" @" O- N. z) n }
3 s f7 w0 S8 c; \1 u3 ] }
' h& t/ u* _0 _6 W d0 n- J1 J9 m& r! x4 l9 j: \
return (maxsize);- Z ^' O3 v' x) x! E& x9 [6 z
}! u$ U: z. N$ x5 J
int dram_init(void)
2 ^* o/ r4 f8 V+ Y% |! k) ^{
, g8 ]/ i# H7 q6 d+ ~3 _7 D; y /* dram_init must store complete ramsize in gd->ram_size */7 O$ v+ X4 C- j0 ?, i6 c! C1 g
gd->ram_size = get_ram_size(: }& n- C0 R9 {: p) W; K
(void *)CONFIG_SYS_SDRAM_BASE,
8 ]$ M+ c: I1 D4 | CONFIG_MAX_RAM_BANK_SIZE);
w- t; l7 l3 O% ]) C% ] return 0;* o( M% |& S3 q8 j P
}
. ~' a! m/ p( U" s4 V" ]0 j: T) M F! [' a! `, D* p
4 ?, W% Q, y* g% y5 j
! Y. x3 T' d8 C; `
% h9 _* C9 n0 ~
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!5 ]% ?* y* W% W! Z9 C+ \
! O ^( x Q# A6 j
# ]2 T' j9 j. r" x$ m+ k* Q6 u! `( n
$ l( F& D4 ]- g! y/ |/ H" g3 n
|
|