|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
' I& t* Y. J! X% O" x/*4 V, I9 M+ f; {- G( V0 @
* Check memory range for valid RAM. A simple memory test determines1 F! n; m9 ^0 N9 k/ ?2 |
* the actually available RAM size between addresses `base' and
. \$ x+ e U# e2 l: b& ^$ }% E: `: s* `base + maxsize'.
3 y5 e4 }3 t0 _. _. H) R1 Z*/3 z D" a/ C! H) F$ d) W3 e
long get_ram_size(long *base, long maxsize)2 u9 k' |3 `& E+ |8 g' r' S
{
) ~9 `* W( s4 \2 | volatile long *addr;7 \ Y9 D6 M* ~: o2 A; ~0 M
long save[32];* P. b. E/ n( r& j; e4 K4 U9 b
long cnt;
3 o4 U9 {# ~- K/ Z8 ] long val;
2 B1 p% o/ d, l7 [. o0 Z long size;3 m" R9 `3 o5 G0 {" V1 [4 z. i
int i = 0;
$ x' F6 v# H( ]% u( o5 a
7 B3 L$ g- q' S" z5 R for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {6 x6 j8 v$ ^+ E) |' O7 a
addr = base + cnt; /* pointer arith! */) u7 y* m+ m+ k$ x
sync (); _# I2 S v* j, a$ V. R/ Q( P
save[i++] = *addr;. \4 G% G8 @$ _' A' g
sync ();
2 Y9 v0 t% J5 |- R/ I *addr = ~cnt;
4 b) V+ q3 t3 Z- X }
) x7 r# g- X$ ^1 }3 v! v7 s$ H6 m. i
addr = base;3 ]: E0 n2 a* _5 V
sync ();
$ v" O. w- |1 x9 {& P save = *addr;7 I+ P, m I6 @9 ?1 C7 e" B
sync ();
9 j) }# m! i0 F9 i& P: i0 K/ E *addr = 0;6 A9 G$ [ p, H
$ s: i4 e x- j7 t; f
sync ();4 b |) T/ V5 n6 P, i7 t% `
if ((val = *addr) != 0) {8 d4 b0 E& i) v$ D+ W/ o2 Z1 p
/* Restore the original data before leaving the function.7 E) L9 M9 w& w4 h! w
*/- `4 ^) C' f7 l8 k* ?+ S4 L
sync ();
# J3 v( g0 B% s *addr = save;6 Y/ u+ G. ~ {, X# J# O
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
0 b! q( d5 K7 Q. a& d: M+ \ addr = base + cnt;0 v Y0 O ~" o; `+ e
sync ();
+ | g; @- }9 j. a# @6 M8 t* R! q *addr = save[--i];2 \: j% \! j2 Q1 j: T& \0 E7 e- H
}
& M# Q9 c: [$ t return (0);
" g; {6 y: a9 V" i/ k } B" v4 {, ?! ~" f' M+ W; ?. \* y8 s
8 J, V1 @" n* a' y5 n' U
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {2 e) w; S; t6 }
addr = base + cnt; /* pointer arith! */
; w0 @3 P5 ~/ `5 E2 d! F+ B& Y val = *addr;
7 S( L- R6 O3 O$ x, R L Y( G/ e *addr = save[--i];3 F6 T, Q, ~- p- A
if (val != ~cnt) {
& A& W2 j) z0 T6 E9 r- L! _ size = cnt * sizeof (long);9 E- n6 g" p h
/* Restore the original data before leaving the function.
' @' J* x( d: {! `, p */
( D+ l" M( z0 [/ ~8 U8 o" \! E5 N for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
# ]4 p& L m) a addr = base + cnt;
+ B6 h/ m# w$ E7 |0 F *addr = save[--i];/ N( J I* [+ Y# [8 I: h/ Y
}
: q3 s5 P& C: K% N# {! U; _ return (size);
: M- y' `/ |5 R4 |$ R0 @ }- }* D: n" i" g9 ]3 ^5 C; {
}0 a/ e4 F2 u5 y& U7 t& ^: y
2 x" E) | w+ `4 ?; N, \ z( p
return (maxsize);3 t) y+ D2 S5 J' E7 o2 E
}7 ^+ z" N2 G6 M. E. R! F, c3 z
int dram_init(void)+ W) Y: E5 q5 f8 E k& w
{$ Z" }0 f% @! J* }4 S# E
/* dram_init must store complete ramsize in gd->ram_size */
/ ]; w# ~" u( E7 j1 B; R gd->ram_size = get_ram_size(
6 `& i2 M/ @/ x6 T% }2 q2 V (void *)CONFIG_SYS_SDRAM_BASE,% o/ b, B5 W/ v& [! k
CONFIG_MAX_RAM_BANK_SIZE);8 Z( U0 c5 C) b" w7 Z
return 0;
* s* Q, J" N- w! J; F}
2 h5 h3 C, F0 B4 V; L1 o8 T, D: ^, o" A; @+ J4 P
) v; s# L- V( O! E& k: f$ p& ^" Y% R$ D' o& ^- S% p. e% |3 v& K
C |& g9 l. A6 l! \, h% MFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
5 T0 Q5 Q* R/ ?. ]* r2 t% f }+ }3 l# o' y& ~
$ f$ O% f' S' H, `" R# l% F0 m0 b6 Q1 E# k8 U; q* Z
|
|