|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
" P8 e; f& r9 V" L& `/* f. M; r# c0 X; |# V6 b% |
* Check memory range for valid RAM. A simple memory test determines" L0 o5 }& W; Z3 k- |7 v
* the actually available RAM size between addresses `base' and' j' K; b% H+ x' m1 g1 F) L5 _
* `base + maxsize'.
9 T. t, V/ b; a% u9 |3 j4 }1 h2 L*/
" [9 }- B1 M4 slong get_ram_size(long *base, long maxsize)
4 o3 u1 e* @( L5 w5 o V; n3 c{8 H6 y4 V+ p. D' E, w& j; c, q: S$ Z
volatile long *addr;
% M: g a* I. c* C$ i8 v! g+ n3 H long save[32];# A0 C6 Q" g* h& p; R
long cnt;
' p% B0 X, Z# e long val;
' k0 z# t) v2 i+ _ long size;: X' ?, I, y# W* [5 y1 g; r7 |- q
int i = 0;
6 Y. X% h5 l* L s7 S
- |' Q2 ?2 u5 z6 _+ _1 M for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {# J) Q( g# b" K+ C
addr = base + cnt; /* pointer arith! */
! X2 ~9 m0 L% K9 m5 ~ sync ();
5 {8 b# F! k+ r x! j' { save[i++] = *addr;1 _3 O& X. m( z2 a1 G0 J
sync ();( i* l( _1 \5 \/ h+ h7 p
*addr = ~cnt;
# V: F; G+ `# }4 M4 d4 F6 y! o }
6 |/ M7 R) ]& M2 e
r5 d) Z& ~+ u" g, I0 P4 ]3 F addr = base;
' w/ g" H3 J" r9 y/ ` sync ();
5 ?' V- h6 x% ]$ U. L0 z5 }" z save = *addr;& L, m( ~8 ]5 h3 u5 ?& ~" s Z0 N
sync ();8 h, y! ^2 v: r# B; Z1 F
*addr = 0;
! y" w9 w- L4 Q. m, R6 s3 y/ l8 D) E r1 e3 h6 X z* L1 T* c
sync ();
4 i p6 L' b# z! ~ if ((val = *addr) != 0) {/ D+ H* C9 L" j- I( ~: q% V
/* Restore the original data before leaving the function.
1 h" l( @ _5 g0 w4 M* w l4 x */
0 `. r% b- o9 s$ K% _' q! B2 v sync ();! X5 w2 l7 F6 _+ s7 R5 X( }% K
*addr = save;; m9 \2 T; v5 x3 |
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {8 a2 z4 E' Y2 x
addr = base + cnt;
0 q/ x" U- S" N/ j Y sync ();
- i1 ^! E) K% Q2 m. ]. {3 [2 V *addr = save[--i];& D8 s# V' \2 o; T+ o/ _6 q
}2 y- J) P6 r$ @: ?& T n0 d
return (0);; \+ y: z2 g5 {1 f- a- c, n- N
}* M/ x, W& T* L8 x" x5 e
; P4 b- I& r. t: {2 Q for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
0 h+ t7 f( I+ g addr = base + cnt; /* pointer arith! */% A8 T" O6 t$ t+ H! A2 a
val = *addr;
2 h& v4 u5 j$ @- U *addr = save[--i];; |. t/ W4 @0 p2 }' A" L3 g+ e% U
if (val != ~cnt) {
2 {- r9 ]. m2 S, N: J' \ size = cnt * sizeof (long);
3 f9 m* R1 O# c$ Y z" L% e9 a /* Restore the original data before leaving the function., P/ P# y5 _ ~1 ~& a% {
*/. w! {2 g9 g7 `
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {1 b( j/ h. {) @8 U0 B
addr = base + cnt;
) C( H$ T1 d4 V- n *addr = save[--i];
" H7 p+ J% |! m/ W: T% ~ }
4 A9 e; `& p2 U return (size);
: F# |/ G' Z7 }0 f% a# M) w5 C N( H }$ B, A! U( y. j- G; ^
}
- e% [/ S7 A. i/ o* x" w+ T: ^- s5 j
7 r2 Q, U: I6 c |# Y6 T7 d return (maxsize);
! f1 G) }. y; _* f, q' }. Y5 e}
) c3 A, q# J2 X; T Sint dram_init(void)
: d+ o6 \/ I$ _, v+ |0 Q) D0 O{0 v' a0 l3 ]4 I: U, V. ~! L5 U
/* dram_init must store complete ramsize in gd->ram_size */& P; ~6 X5 ^' a/ n# m+ ]7 M* o" O
gd->ram_size = get_ram_size(8 C; j9 v, E' V
(void *)CONFIG_SYS_SDRAM_BASE,
9 y( Q d5 e. \( u& `; \$ Z! T) z9 p CONFIG_MAX_RAM_BANK_SIZE);; @( ]' N& `5 u) S' d0 U; q
return 0;
$ v! j! X! J, C5 v3 Z4 |}
; k+ Y U/ P- D1 m& p
; E% K2 ]' o) y) e/ M( L' E9 s( y
, ^& R7 u4 U: D
! e/ M* p& [, @- C& g( a0 b7 N0 P' g5 Q1 b* D. J3 d+ M6 O$ }& [
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
, P, n o0 l$ k2 y( `$ B$ r$ A1 X* }& s* w/ g9 U. V
7 n* O, w6 d5 J3 `1 g7 S# t
) t! w0 `- v9 r- x9 W |
|