|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
; G0 V. K5 w* I' Y% u/*
: n- y4 Z" W6 V6 S! @( G0 }# D* Check memory range for valid RAM. A simple memory test determines
& j0 l. N! `" X, y; n) m* the actually available RAM size between addresses `base' and4 x3 | R% e# V8 W
* `base + maxsize'.4 |7 h" y. B) s# @2 k. Q
*/
, H, u/ [7 `( R- \) W$ ?' R3 hlong get_ram_size(long *base, long maxsize)
7 s2 v1 H h' B9 r{
, v5 t: u8 J- ^! x! Q8 u volatile long *addr;6 x& d" u8 g/ [& j/ k" l. T/ d
long save[32];: z! t, y# _3 H: ~
long cnt;; n& \, y7 L) T; p
long val;
" u) Y9 p. F. F7 y* N long size;) o7 ?4 w2 L8 W& I
int i = 0;. F% |, p* X2 W$ A
7 l0 q$ _9 ^- O; Q( G for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
$ R2 ]. j6 ^, [, a/ Z9 t addr = base + cnt; /* pointer arith! */
$ Y6 _ ?% t$ T0 U7 `, q3 c sync ();1 S3 i5 F C4 K+ \6 p# N- o
save[i++] = *addr;9 S1 R( ^4 M& ?# {9 z8 x
sync ();
" h ^: w7 P* \' S2 t *addr = ~cnt;
. ]5 W4 [. e+ ?: Q/ b' O$ Z' h }
2 ?5 @6 a1 P9 M0 V
0 N* z1 h/ Y9 M: k* t% b addr = base;
# z$ @; n* r! }0 I/ u sync ();& s7 J9 s4 F9 l5 f1 W& F3 s
save = *addr;. P# x6 T! I4 y( ?' e g
sync ();
1 a$ I5 ~/ \. t+ L# t5 T2 K' n3 g *addr = 0;! n [; i% I( C/ j/ E
9 U4 U) i' m7 [! ?/ R sync ();
9 W( g2 s" }! [" H9 H( y# a3 W if ((val = *addr) != 0) {5 a6 ~! |, G7 X' \+ S% ^
/* Restore the original data before leaving the function.
- }' ^' y* {( z( I */
* O3 h+ I* E2 z sync ();
1 J' _* m* W2 w( X *addr = save;
& o1 m2 a4 G' V" y2 |; l* |9 e8 e for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {9 ?8 ~; h* b. j, [; t, `
addr = base + cnt;5 c( M3 k `' M. n
sync ();
/ u( F6 t: C/ L% k *addr = save[--i];
, ?6 C% H6 i6 w N* [9 g }% b' f; [5 ^6 c/ Y) X
return (0);$ y* n# G0 [1 y! Q8 ]+ v
}
; ~/ i I R9 v% z( a
0 a" ~" p* g, d- i3 T4 }3 r, P3 q; q( d' n for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
5 g7 t4 i* O. o, e, ~ p addr = base + cnt; /* pointer arith! */' v! S! d* k: w; q1 G
val = *addr;) e, q5 K8 N/ s' x( M9 }
*addr = save[--i];4 z( x! L, V9 Z& Y' W1 O3 M
if (val != ~cnt) {
7 h, d$ t" T- w: i- ?, E size = cnt * sizeof (long);4 _2 W% V5 f+ E8 x9 V% D
/* Restore the original data before leaving the function.* r' L5 I- y/ y# Y% J
*/$ o6 P' F! I6 s" E! y- z
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {+ R2 f$ H( @- g- o" E# Y: a
addr = base + cnt; u' z7 V/ u, C0 h
*addr = save[--i];0 R9 I. ~3 Y5 z1 E: y0 U9 D2 `7 `
}- p; n$ U+ Q4 R$ r7 n' j
return (size);3 G, H+ m3 V; @9 z0 p
}( h2 o# T$ _! V! I
}
! X; H! \7 u; y: U: [8 @" H& P
, Z, L7 X, m. j: }, F } return (maxsize);4 U9 u( r7 @' N6 B+ I! }+ u9 Z+ m) W. z
}
* t1 h$ {, O1 @% zint dram_init(void)
" l: N: ?- Z) o/ d9 i6 A9 ]& e{
+ s* i! u! x, s9 n, ]/ ~ /* dram_init must store complete ramsize in gd->ram_size */
) K5 e4 \4 J1 }) ?' j gd->ram_size = get_ram_size(
& J$ y0 _" @) f, q* s (void *)CONFIG_SYS_SDRAM_BASE,. x% B3 h- p+ _0 n. M [
CONFIG_MAX_RAM_BANK_SIZE);
8 B" G) `2 D( \ return 0;
2 b( B( x7 U% { M$ [- J6 j( y0 M% t}
3 |9 i3 j; W0 ~& |% i0 y4 \' s+ @! K o
! ~2 T* [6 ]* H8 e) ~1 A" x
5 A" ?0 d. Y6 P$ n$ p
$ ~; o }$ i+ A! i8 x' wFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!$ H1 s9 W6 m, Q7 _! B* B* V+ \
/ x+ j8 X8 E0 J* h. u/ f
( [: H( q$ y" o( u1 r
7 Q) c8 v) _( y/ q: F) a7 T |
|