|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:) |5 |, c I4 N5 Y% _
/*6 b, o; f: x5 K3 ^2 e% ?; h+ L1 i
* Check memory range for valid RAM. A simple memory test determines( m* a' F" ]- ]2 }$ f" D* S
* the actually available RAM size between addresses `base' and6 A7 I) e4 E: a, J3 n" {+ \7 ?
* `base + maxsize'.- [ B4 q4 _; @
*/2 q5 Z4 X- m5 q+ D# ^
long get_ram_size(long *base, long maxsize)+ l; q5 s: p4 t; d
{* R, k1 A; j5 H" ~/ {2 g
volatile long *addr;% }7 [) h3 Z, N9 n7 L8 f0 V
long save[32]; C% r/ o; n( E8 s# E* C1 Q2 g
long cnt;9 n3 Z; Y+ D- N1 q7 M* q8 b
long val; ~( q7 U. [' j7 ~! J7 W% r
long size;* q: C Q9 d6 h( l' N
int i = 0;
0 h5 [. w: Q! [: {% i+ i# h& @ t
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
. ~, P5 ~9 b, C( X, U6 F5 _ addr = base + cnt; /* pointer arith! */5 N* d" g1 h0 z! V/ d% n+ U/ _
sync ();! b+ k3 m5 Z! `/ Y$ |! Q
save[i++] = *addr;
; j1 ?1 M# C: `) {: W- x/ ~ sync ();$ n8 m' j6 c8 X# J$ v
*addr = ~cnt;
+ |9 F F/ G y7 r }: T. U6 j9 }! K" y) v
6 [5 Y7 `, t# n
addr = base;' Z! K+ A( M: y3 @
sync ();
' u+ y. P. d$ S$ e save = *addr;
, R4 I1 d% F( g. E- ~/ o* N7 } sync ();* W$ I4 ^1 R6 L) {. e$ c) @
*addr = 0;1 G5 _/ c( F* ` p
$ W, V2 Q) _, d; T W
sync ();
. H1 @( q( h) d1 U4 D' d% s if ((val = *addr) != 0) {) U; D* T Q. g& _1 R5 m/ ]" F; x
/* Restore the original data before leaving the function.
! i/ @& |& x2 c */ [7 I; R# @" c, C
sync ();
1 ^0 @; E$ n9 J( W, v0 \ *addr = save;
* |: c' O3 W! \# c5 k7 C for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {: j! n- y R, }6 r9 r, g! ~; a6 f
addr = base + cnt;3 y! Q% m; @# H8 g4 V
sync ();
# `6 E# G. g1 q& ^ *addr = save[--i];! X/ H- H; L& P m" B2 X% }
}- ~. M3 a+ \1 o9 B
return (0);
' H% ]( D$ o$ l2 ?6 X }5 N) ~% |$ B) W/ a2 M3 m6 |
: U& ~# k8 v) Y for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
& F h' S( \) s4 r K addr = base + cnt; /* pointer arith! */8 l' `' }- e+ A
val = *addr;' @% x% t6 G1 ?8 ~5 D0 V. G
*addr = save[--i];
$ D$ J5 `( u. V( D5 J6 O3 P7 } if (val != ~cnt) {
4 M+ [. y- o6 b. N, K size = cnt * sizeof (long);
% U9 @4 J, i/ m. H; J /* Restore the original data before leaving the function.$ A5 ?! f5 z0 ~7 Z& [: l
*/9 _ C" l* G Q- B! R; \
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {1 d, Z7 B+ l+ @$ o% j/ ]
addr = base + cnt;
8 Q p( p1 m n" u9 e8 K *addr = save[--i];2 b* e# A6 {2 b9 w( ?3 S
}
/ p6 G6 g, b8 ~+ P4 r0 H* G return (size);/ _8 s+ W7 z9 O+ I% `8 r, s! B, M
}
. d i) P8 x. P }4 J$ j% R% n" q# w' X6 e
3 ~9 j, q# ]8 X1 _ s- c
return (maxsize);
2 X" ?5 [7 o, R6 M. W5 t) A2 g}
) }# Z& t. i" }8 i3 Cint dram_init(void)
5 }6 \3 U. X- u; A5 a* t, W{
3 Y. F2 n! A2 ?' s" n /* dram_init must store complete ramsize in gd->ram_size */" {6 @9 W+ ~' o8 e: H* A3 r3 A
gd->ram_size = get_ram_size(8 U6 V; Y$ U1 ?; v
(void *)CONFIG_SYS_SDRAM_BASE,
( r$ u7 I3 z2 B# R8 Q CONFIG_MAX_RAM_BANK_SIZE);8 n6 t9 h9 T! ]: M* t
return 0;
/ E+ B- K6 G4 d) Q% n}: q4 Q4 g; [6 B4 a( n
' }$ t+ m4 q" j& R
: O* m% x- k4 e+ w! g% q9 i0 U# c1 `- V1 `
, @2 r, h6 o! ^; r
+ D; q% _0 k6 S7 L- u" d
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!+ e* z$ Q! W+ C& J- }7 t
1 V- ~! g. ?" G' T K8 b! L% C8 G
! r0 J# \$ @) k7 X2 ^
' ~) e2 Z5 t1 f2 k |
|