|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
; \$ h' M3 T8 s- j! R1 O6 ~/ v5 n# l* v4 y/*, G, H. w9 X0 m+ l) |1 w
* Check memory range for valid RAM. A simple memory test determines$ {$ T! X8 {" S' [. v
* the actually available RAM size between addresses `base' and& X7 P6 V+ M& }2 L( b9 ^* h$ ^: k
* `base + maxsize'.4 J& z3 X1 H! J' `; n& e
*/& M% g) i4 Z5 L0 q4 n) L
long get_ram_size(long *base, long maxsize)
( `- S- c$ J" g- x" Z{
& g, J. a4 V( M# f volatile long *addr;8 I$ L% ^" X' j. h4 _3 d9 s, X2 y
long save[32];
: d7 ]5 u( `6 \( j/ c6 ? long cnt;+ N) R) Q4 C! n" M' k' Z
long val;4 \+ s# m+ }2 u& c$ l3 r+ O
long size;. C% [0 N8 ^$ t4 z1 S
int i = 0;
7 k" ^/ u* o0 o1 _! Y* }0 N& A
2 R, T5 i! ?& K# c" n/ K, x9 f" V for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
& }" Z+ S1 f- | addr = base + cnt; /* pointer arith! */
1 S, Q) Z5 c) i2 `7 ^7 o& @ sync ();) j6 ~7 k1 w) g8 X1 \' P
save[i++] = *addr;! j& ^* L% z j& `: \
sync ();
) _. c/ i. ^7 Y0 a. ? *addr = ~cnt;
9 e& D+ F% d: x }) d) I. j# T2 I7 m' p: L
$ W/ P. B# @+ j addr = base;9 q: s8 d+ U: [, L9 C! w; t+ h
sync ();# U5 n2 c9 x1 L8 r# p1 O: E
save = *addr;
$ \9 X# b& K% P sync ();
7 x# _3 W& x3 ?+ u5 j3 r *addr = 0;
Q9 f U, d) {
$ L/ r% T1 k/ @+ k d sync ();
8 ~( C7 o) a* m9 D; o2 G2 u if ((val = *addr) != 0) {
' c! X! K4 f. B /* Restore the original data before leaving the function.
% f/ J2 K; D3 Z1 v1 p */
) K( [7 h" f* o, h* \ sync ();
2 I! D( L& O) b. p b3 j *addr = save;8 v: q c, e1 e- ]8 f
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
7 }, B+ `4 \. x2 ~" f addr = base + cnt;" Z9 t- `; \9 w- A: _7 I, d
sync ();
' @: h1 M0 ~1 v$ X *addr = save[--i];
& @# n: C" G) q5 z# R0 L, x }
! F3 }! T1 ~: C) U# G return (0);3 _3 A- d5 H6 H0 |9 M c
}
4 U* t2 k+ a' q- V
/ D. @5 ?+ c1 R: j8 A& y$ C! c" p for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {0 g# q3 c4 ?- F: ?) O: x0 P
addr = base + cnt; /* pointer arith! */. ~2 q9 U8 s' |* u' ?# N8 z+ @: A
val = *addr;
7 K1 ?: @( b; G1 r. k. A/ I *addr = save[--i];6 y5 f* |& Q2 [4 w7 N! @6 T0 y
if (val != ~cnt) {
# m; g B3 @) S2 T( ?4 Q+ E5 e size = cnt * sizeof (long);& p/ o: `7 |7 T1 k& |7 T8 T ~( L
/* Restore the original data before leaving the function.
; n! v$ D, G$ l! {6 { */
" b! Z% Z) F7 i0 y for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
6 g, j! L( b j0 Y! f4 `4 a- { addr = base + cnt;
5 G2 `3 x- A0 U, o *addr = save[--i];
( A5 K V$ V2 Z$ Z5 ^8 q: h# `) p. p }
; H& q& _% r: K/ @- b9 j return (size);6 [ c( j/ {0 i m/ d8 R- B
}( j- t. B7 ], {) S; Y: Y0 s
}
v( u2 Y1 M, ]6 N# {7 y: p2 k
; U a1 R3 |! j8 f9 ^' n return (maxsize);% g) J) K* B- b# }
}
7 P$ O- {7 P. o/ a1 _( z0 ?int dram_init(void)$ E$ p5 T7 y. S# Q( D
{
$ P5 k# z; ]' Z% S /* dram_init must store complete ramsize in gd->ram_size */
) Y m& {% f9 ` u' O* y+ l gd->ram_size = get_ram_size(1 f+ G; c( o2 a) Z6 f! |, }3 g
(void *)CONFIG_SYS_SDRAM_BASE,5 X8 I4 I& K* ^: a5 j0 \- d$ I9 ^
CONFIG_MAX_RAM_BANK_SIZE);/ { s- j _7 I6 E8 c% j( W5 y) B
return 0;
" ^0 r5 K& E& l}( z7 w L8 C a( J8 y
* ?: y0 p( S$ i4 f+ s6 |
! f+ `/ N" q x" o# B9 l c. @4 T5 A% `
, b8 e1 B! ~4 B' j; HFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
5 @0 r' n# l8 e: G2 A6 D% [0 {: K7 g) v. O0 W0 u' V- u
4 o' e4 k/ T$ p: X' I
2 Z8 s0 z% j( T" n* ^. |9 Q, o
|
|