|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
* F* W' Z/ z. Q8 [" N8 @/*& u2 S- L% Q, ^. m; G! ~6 C
* Check memory range for valid RAM. A simple memory test determines: _4 }$ F1 D7 W' r6 E+ W
* the actually available RAM size between addresses `base' and
" Y: c7 A/ @1 {3 l( _: a8 `* `base + maxsize'.2 ]' \1 t4 s: z5 w. U: M& s
*/- w4 S. t' H* p+ V( n
long get_ram_size(long *base, long maxsize): @# E$ d) V1 f5 t0 }
{2 o& i+ J+ h0 D: S% [/ ^
volatile long *addr;* p! d* h: x3 o
long save[32];, d% K$ |+ p: ?: `: U5 R! m2 Y& @0 k
long cnt;! h# E4 |- U$ Y( b% d4 Q% N
long val;9 }- c7 ~, s# N, L4 ?% `9 w( }
long size;/ E ^; {0 z1 L x" u5 i
int i = 0;
7 U; n, z& W5 D$ j+ q# i
6 S6 }( I' d4 m& ]6 X for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {' X' q) Y4 ^7 r0 @
addr = base + cnt; /* pointer arith! */1 N# R: F5 Z0 U, ]- E6 ?
sync ();/ Z' N; {! f$ i6 i* U* `1 @
save[i++] = *addr;/ A/ v6 T; I# {5 t/ g; E
sync ();/ D* b- ^$ f* @2 P7 P. G. A
*addr = ~cnt;, M$ p4 s( p2 n9 R
}
) n7 \% K0 _+ v0 B' ^7 l9 p+ b
& n9 Q& z) u4 I. k: l# [ addr = base;/ H2 r3 s, r! y& v5 S- N
sync ();
, @% G/ L( X* o; ~ save = *addr;! l2 v6 _2 t9 Q, K& B. W& @* S/ I
sync ();
g( m; t. [6 J' O! _" I5 ^# p' M *addr = 0;
* y2 v0 e+ r. j! B4 V! d& m# X% d, U. J9 p
sync ();
, `+ w8 y6 {) Q: [$ ]2 k% T if ((val = *addr) != 0) {
; s/ [0 L' W5 ^- k+ W4 d /* Restore the original data before leaving the function." R" s, Q' B- {" {& v# |- Q5 \: l
*/
( U) W( r% K2 i# L" Q# O2 c+ { sync ();) C2 P6 B/ U: C. w B
*addr = save;
$ [* J; K" x( s! ^# B x' Y6 S for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {! k- x) h1 V! S! U1 m
addr = base + cnt;
& Q8 H- W" Y; E/ P' d sync ();
# f$ l, h9 `" A. C2 p' o4 G9 I" ~ *addr = save[--i];
* @' q$ r) [) P( D }' A# n3 R) \9 }
return (0);
9 }! z& p7 p# w* `+ V }
6 t" n8 q d5 ^! f" r7 E$ R3 r0 I
. u/ U7 q* W, B, ]$ Y for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
6 n) A8 [! x Z$ d3 A addr = base + cnt; /* pointer arith! */
, W& b1 c0 U0 m% {8 B7 _, c val = *addr; ]) h2 A# c9 O
*addr = save[--i];1 J% L: _' ~- R& V
if (val != ~cnt) {0 N/ S; ]" v: h* Y* a# t# {
size = cnt * sizeof (long);( Y" S" M$ N) P& ~: C [
/* Restore the original data before leaving the function.
! d4 o; h6 U& ^- {3 n- P. R& X */
; z A1 N% l0 E/ Q# t$ a3 @% ^9 e% g for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {9 B+ w- J* Y( c* P( o& O5 f' S! v
addr = base + cnt;9 Z/ g" J0 {' w5 S) Q( l# a$ v0 _
*addr = save[--i];
( z: K# f- P( {% Q }5 Q# M6 K! Q* Y
return (size);
( j& w: q p5 L7 O( P/ H3 p }
0 M: {* {4 j) ]$ _ }3 X; A0 n# D% P. `8 M
' \4 ~$ Q$ c9 i) A
return (maxsize);
4 S* A5 i9 O ~% {2 D, t1 R}3 V$ \7 a/ ]( c4 w' g
int dram_init(void)1 l; b9 N( Q' E
{5 n0 h# ?3 S9 l1 d/ l
/* dram_init must store complete ramsize in gd->ram_size */
' g8 S: j+ A4 ]8 @, l A4 A gd->ram_size = get_ram_size(0 h w& w8 l0 C- F2 }$ N# I
(void *)CONFIG_SYS_SDRAM_BASE,
- M B0 s5 X& T, K" J5 _* d& h CONFIG_MAX_RAM_BANK_SIZE);
( W- ]9 a1 t8 n, P1 n& x$ U6 P7 b return 0;
' U; U2 I( V* Y5 h) S% B) T% k8 M( {}9 E9 f6 V4 A# g5 J& w; B$ W
7 G4 u# v- ]& ]* \
7 b/ r a3 b5 o, `- o3 D
2 A+ o5 L" ]5 `) O) y
- { l4 ?% b2 ?7 e# h! tFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
7 w* n* n5 ?0 Q8 E+ g' \+ z/ ~# H- D& k8 o+ x: J7 |
& O2 A2 b; w% {! w& b0 T
1 ?8 e- A/ d" A8 p+ D9 O+ d |
|