|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
! k9 o, R2 g, @/*" I Y; t8 D- B% d. X, R
* Check memory range for valid RAM. A simple memory test determines0 f) t( p2 z: z3 w5 U
* the actually available RAM size between addresses `base' and
' \4 D% s u# n |* `base + maxsize'.
, N0 X: ?/ |8 W3 Z4 L# s1 T*/9 [7 A u+ s1 l/ @1 }8 }6 R
long get_ram_size(long *base, long maxsize); d' L- _# f4 M2 M Q; w
{& c) J- P0 K* F7 i' u9 E
volatile long *addr;
; W8 k4 ^1 \# f3 N2 c8 e3 U long save[32];
- M' f" q' N f& q, a% j long cnt;) I0 ~1 r" E; _7 r; t! j
long val;
" j: w/ W9 t5 u7 k3 J long size;. D, F& V6 t/ s& H8 ?+ P7 ~
int i = 0;/ _) M4 s# _# W' S
" H: Z; m$ u/ G2 I+ b, g6 Q) V& N for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {- p: q: B4 \ H% T) k ~
addr = base + cnt; /* pointer arith! */- }3 x& [. x( @' `3 A' @
sync ();
. t; x0 Q+ L5 O; [# G save[i++] = *addr;
7 e1 A! K0 V# g/ N$ ~+ Y sync ();- I% b$ m- ~) f8 d
*addr = ~cnt;( g, [: |" I) S
}! w% n1 t) M) ?- R8 f$ }2 D# `
9 o& Q1 s, Q. p1 o1 ^
addr = base;# A E5 C- b/ l( c
sync ();
- v. M/ @8 F$ w z' t save = *addr;
( `( M4 c9 P( M- r/ l sync ();
6 |* F6 ]1 f# E; h *addr = 0;
/ w* Y3 K) o* H( n& b: S; p. \7 m4 m6 B* A( }
sync ();" l9 M/ k5 n6 \% @0 ]- I8 Q c
if ((val = *addr) != 0) {
8 w4 D9 D% s6 \1 N; R$ j /* Restore the original data before leaving the function./ b& y/ ^! W& M+ i7 R
*/
' J7 [7 L, W$ [/ w% L sync ();
3 b# F3 D& _3 }6 J) Q) Q$ c. c' q *addr = save;
- N& s0 ?, {' T% X0 J0 x0 x for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {. M2 G4 p2 F4 P: K& g: t" u6 k
addr = base + cnt;
4 r! x& ?4 J7 @# l9 h! f sync ();" S& q0 e; l; _- Y. C! P0 @9 d
*addr = save[--i];: B' P% N4 f# H6 Z) k7 Y" Q
}
# Z8 O0 \" f( |% {- x9 k. F return (0);
5 S X- ]3 T8 X }
* ~- T, M3 ?" C" d2 j% n# ^8 {3 ?: {5 b
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
1 B' G0 i+ ~% y- N( D addr = base + cnt; /* pointer arith! */5 A9 d' f6 ]/ I3 E
val = *addr;& ~( D, d: k/ w8 \0 J8 p
*addr = save[--i];
/ j ^5 q4 ^) S9 f$ n if (val != ~cnt) {
+ a7 p/ ]4 w. x/ i( i( h size = cnt * sizeof (long);; k+ ~2 y/ v: }# o: n
/* Restore the original data before leaving the function.5 Z7 y: U4 z" o0 R c+ V
*/
! E- i9 a6 d% f' v for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
9 P* {3 f1 J% e* E1 _ addr = base + cnt;7 W( y! u, Q! k+ ~1 e. j
*addr = save[--i];: S9 v8 a: }- D, o
}2 A$ x% e" a4 J |0 `
return (size);
5 O# r# M i8 L' x3 e& G& b }3 Q. K7 F- |8 V% a' j
}' A( G8 j' C+ n% ]4 L
5 A: y- o6 c; u' c. O" i0 R1 f
return (maxsize);
4 B" v1 u& ~ y m; K" [: F0 k}) T/ b! q3 E( g/ C% a
int dram_init(void)" T, {1 L, M+ `
{$ }* X2 G# u1 _
/* dram_init must store complete ramsize in gd->ram_size */1 q- p! M x. J O- c- S p$ x
gd->ram_size = get_ram_size(
& N8 }& S7 E5 q. ?/ p. |+ X (void *)CONFIG_SYS_SDRAM_BASE,
4 V, y+ y1 ^) O$ M CONFIG_MAX_RAM_BANK_SIZE);4 ~3 W: t/ v4 x. M
return 0;1 X9 l8 Y' n' b$ ?! W/ r
}/ M) v% o7 W# k" W' o% ^' E& X" ^
( v- q' w$ U( x z
$ y! b& m, s; p. x. v- i9 A4 D. Q) L8 X6 s( [ v
1 J2 A9 P. K# l0 Y- p gFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!/ A, p1 M9 K- k5 m9 \( \% V+ t
8 R! U3 a- O1 h2 z; n3 [8 N
% B& ^' v' R( v
6 u7 ]: f1 Y' a3 y9 ]% B3 ~- L |
|