|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:. G0 h7 v- {6 O
/*9 O3 N0 ?- m9 w/ X/ L
* Check memory range for valid RAM. A simple memory test determines# O; b+ t1 z5 h: X
* the actually available RAM size between addresses `base' and
# f7 w" h9 U% V" [: N. T+ C* `base + maxsize'.0 c3 F0 a/ S3 g' b7 s5 [" a( N
*/$ O- _0 E0 A+ j) t! R0 E1 `- R
long get_ram_size(long *base, long maxsize)3 ^" F$ m. }1 [" S0 Z8 p
{" Z: ]0 x: Y0 t, K
volatile long *addr;
& @" g% D, k0 }" N long save[32];* y3 u2 }5 V) p1 [
long cnt;3 T+ ]* }4 }# X7 A+ |, s
long val;: r9 s% L' m) G: M( x
long size;
7 v4 Y" U! V: u int i = 0;
8 \, _0 r0 E8 R2 }; X N4 _$ t
+ v+ b1 w, ]( x5 E) V2 f for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {1 T* n9 _: X! x! Z# A: x
addr = base + cnt; /* pointer arith! */
; L+ N7 [" F r/ I+ G$ A sync ();
9 Y. X6 {; A q. c& i save[i++] = *addr;% R" }. a; }* ^5 O3 v6 @: _
sync ();
8 k Y9 }( x. A/ H$ i& O. v" K *addr = ~cnt;
2 o5 B T7 O: H# e C }
3 i! C% Q; X, l5 E# |& f" ]4 ]1 B' k: x0 k" p" [
addr = base;
; ~, ^ n/ I0 _ _* \/ r7 p+ x) i9 X sync ();
7 X% C' F/ v' X save = *addr;
# G* x. H, d) }! V9 z# Z' b sync ();
( M; n, }6 b7 w, E% j& g, S) \/ P, U( [ *addr = 0;6 m0 D- h- l3 Z8 P
6 Z9 M! V) e" l5 o: e4 J
sync ();
& k) K, J$ y9 F# m if ((val = *addr) != 0) {& j) ]0 L4 ~7 h7 R9 l' S
/* Restore the original data before leaving the function.- v8 Q$ \' {" U' `" Q
*/
; G l, }: x0 k sync ();
4 [# M9 s6 h1 I9 h1 M *addr = save;/ k6 l, S) p: a) b1 C
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
3 [1 F9 u$ S" I! { addr = base + cnt;$ O' x- y: Z- d7 W0 W: Y$ Y3 F' e
sync ();9 _2 g* S3 y C
*addr = save[--i];) L) k, M, q& ]" E
}% p$ j2 w3 Q# ^" n9 e; o
return (0);
+ n6 K @5 p- V% k8 X& E }2 Z- o% m0 q% j1 d5 `2 k Q( p
4 M! @* A" ~) C5 M6 {7 {
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
2 D# G, R& @9 e' ]4 S addr = base + cnt; /* pointer arith! */
7 }$ e$ {/ c g$ ]- T2 b, p val = *addr;
; ~. q U+ e& _6 G E *addr = save[--i];
% b' r0 K7 H7 N, L if (val != ~cnt) {
5 S. k' R* Y# c0 `4 ~/ | size = cnt * sizeof (long);
% u2 {3 M. @. o! |4 d; ~) O /* Restore the original data before leaving the function.
/ ~- F( n3 X1 m$ @- C7 Y */
$ c* g: t- K+ c+ W: e for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
6 ?* L% z1 l* P( I addr = base + cnt;
; c6 I( T; V4 H0 n *addr = save[--i];$ S* E9 I6 S; n+ ?6 q5 V
}4 R8 \- Y' L1 \* y3 R: Y/ r5 e( d
return (size);) e! s; A( M! j, A/ A4 Y0 d# T
}
" d7 |' n: T& m5 w; K }
0 f4 t' O' ]1 f: R/ D0 P( H# T r2 u3 l" X5 x9 q: x; C) w
return (maxsize);, O. Z m# s4 V+ g# L
}
) Y/ U; E3 ?8 k: Dint dram_init(void)
6 P( s1 u Y0 T$ _4 l, `! x6 ]{
. @! \6 P! T; L /* dram_init must store complete ramsize in gd->ram_size */
* g* B- j9 h, g. \$ M4 V. K gd->ram_size = get_ram_size(5 e2 R; t. F, A4 m
(void *)CONFIG_SYS_SDRAM_BASE,
1 w5 I* O% V0 `4 a! E" p) ] CONFIG_MAX_RAM_BANK_SIZE);
1 M: X$ y U7 W9 t& P return 0;
( v: j% l$ R2 {- Z. W- ^! Z( l2 _}* x$ U; q5 f: M; I. O Q
8 I) M) I4 {$ P$ K) S6 ]' t' x4 Z, ~4 A
* s3 Q, q Y5 F$ ]0 k) A9 K3 f% O
& u7 }! j. S5 MFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!+ O+ l* x( ^ z; m/ v, Y
, T/ {) l) u k4 w" `1 X$ @5 K$ Y, h
0 D8 A5 E0 J2 |
|
|