|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:! Y9 E0 h$ h2 C7 }2 x/ P* R, R7 e
/*
& X' U. _1 c& t* j6 z1 P* \/ O4 W* Check memory range for valid RAM. A simple memory test determines4 p1 E5 L) A: A! H$ Z
* the actually available RAM size between addresses `base' and
# F& D3 c1 p: ?( M8 k6 n5 j& h* `base + maxsize'.0 f" R( G4 b. Q" v" I
*/
- J6 b5 E2 Z( L) ?# c3 mlong get_ram_size(long *base, long maxsize)
k- l0 U4 \1 b' n# L) e{
: Y4 ^) N6 P: l% @! [ volatile long *addr;
; {/ C% y0 o | h5 D R* a6 N( B long save[32];8 x- o) u( l# W* c& i5 i
long cnt;' d* s! ], E0 ^5 Y% o5 o l
long val;/ p3 j5 x+ G6 \% p% u; ~1 D
long size;7 h# f6 N8 F& G. c
int i = 0;! r: o/ l# d4 R8 q5 s% z/ R
; {- c3 i w0 ?+ | b5 W7 d for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {6 V Z- o" G; {. U* T4 e
addr = base + cnt; /* pointer arith! */
9 K* b7 n) u6 l% O2 j& a. D$ H sync ();. p( d t+ n- @6 c( I. y# w9 ]
save[i++] = *addr;! E4 ]+ D) X# b
sync ();" v3 B+ B% b+ J0 j, G! S1 ?
*addr = ~cnt;6 T0 ? c# z: Z+ \) |- @
}
$ X" n1 n7 @0 H& C) |" \ e) R5 w# D
addr = base;
' y3 B1 i, l6 ] sync ();
0 E6 ]2 R/ v, S. \9 Z save = *addr;: g3 z" e# M+ b# i! U
sync ();- \6 n$ ~" j. E) \
*addr = 0;
8 W; F* d0 I6 c+ _: u+ K4 u( p0 f- ~ `5 O$ K9 g
sync ();
1 |/ {8 [: }8 B# k9 l+ J8 G4 Z3 C if ((val = *addr) != 0) {
+ R {/ t; R: M. k /* Restore the original data before leaving the function.
9 q/ t: m" O0 w" H: z3 Z */" @5 O* s/ P" P: \
sync ();4 y2 [7 V9 m9 T* k% M& ]& y
*addr = save;
1 q, O; o# P. R& `- h8 z; B9 G for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
- @! h/ M* K7 f2 X( _3 ] addr = base + cnt;
) ]& i( H% {" I& e: @4 E sync ();0 I8 g! [% Z# K" {) O# d7 U2 q R
*addr = save[--i];
5 b0 ?& X8 u$ F3 K3 c. \ }
H: F/ ?* c7 Y; P7 T0 G; U return (0);& X& _( o; @, f5 T3 b% T# ~& J4 n- ^
}& }5 m- O: j$ k$ s6 c
5 S9 Z+ Q1 t2 H+ ]
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {# T$ l4 O3 _; r9 X' C
addr = base + cnt; /* pointer arith! */! B8 W: e" H& A2 k) c# v9 X
val = *addr;
. @0 x: e9 y8 h R) b( ]9 i5 x *addr = save[--i];9 K" l/ g" f& U0 M- k0 b$ P4 k- N
if (val != ~cnt) {. Y9 `3 X% J' s L* q
size = cnt * sizeof (long);
) z& z2 [7 P+ a7 I n. z /* Restore the original data before leaving the function.
2 ^1 [/ B; k! v */
% @8 J) y- L, j! R for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
5 G, d& g0 h5 D i0 |& O addr = base + cnt;
4 H$ `0 F" v- h# i *addr = save[--i];6 n( n7 |7 v$ ~: l; d' V6 p7 @
}
/ D/ e. V1 P3 s O+ p return (size);, J+ W2 \* _8 _# @) n# X4 j3 {% M
}
% L- Y: P4 r k! x o1 C8 T }
8 {8 s" j. R* q, i( C/ z$ H( D; ]* H9 M1 v7 ]
return (maxsize);
, N3 X0 w. C r; ]# S( l& J}
; q2 s3 }* S; e# y3 dint dram_init(void)
7 `* n h& P1 k/ q/ V- ^{
8 T+ \0 M* Z4 O /* dram_init must store complete ramsize in gd->ram_size */
9 A# C3 B& x7 d6 r- w: Q2 S gd->ram_size = get_ram_size(: P% K7 A6 v- T& ]$ I6 Z
(void *)CONFIG_SYS_SDRAM_BASE,6 U7 g, A" \4 f2 z7 O* R
CONFIG_MAX_RAM_BANK_SIZE);2 t) r# ~6 H( p8 l. Z
return 0;) a" u9 ^$ D" G+ V O' H4 q* j
}8 M4 y8 k5 Q% n' i
" c" M* T; N$ a; B$ y
% l3 X: ^2 U8 O- x) `
3 I: p0 u4 G' x/ q
( i- h: Y* R% I( m5 B$ I. J* oFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!1 h4 H; Y/ K/ E. I0 j
, I) O1 X2 ` }3 h! Q
9 H5 R4 I2 A$ e; N6 l
+ x% g1 ]7 f4 ?, n3 o: k4 n/ n/ g" L( ? |
|