|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:/ t9 O s4 V; z( U
/*3 v. K0 J ^# @0 u- x: K
* Check memory range for valid RAM. A simple memory test determines
& O' u8 z9 }! o9 O* o1 w1 q3 B* the actually available RAM size between addresses `base' and
' B1 `' D3 ~8 E" O* `base + maxsize'.
9 O$ {; m# d4 i3 @*/
# p& i" w$ v4 U9 Slong get_ram_size(long *base, long maxsize). N, }& ]0 L9 n! S9 M5 V
{& a8 r$ C1 J+ i8 l: f- r
volatile long *addr;0 D- G1 ?% l0 i2 H, g" S$ Q/ B! n7 F
long save[32];) Q2 l& T j9 q+ s
long cnt;6 D& c8 t6 ]& f
long val;$ T7 D$ t k/ Y& I( U6 P
long size;
$ R! |# V: Z0 D* N! T4 h& B- ?$ j int i = 0;
1 i& Q8 I; a9 R0 G( m* B3 V" x: Y# `$ g9 q- y3 `
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {& \7 `# w0 K# s% o9 u3 l0 r: B
addr = base + cnt; /* pointer arith! */
# ]& W2 T4 b4 A3 ^8 T+ _1 a sync ();8 f5 X$ i1 d% Q$ p. g. v# H
save[i++] = *addr;4 d/ r; J. ~; R* h* c7 m% j0 T7 e
sync ();8 a, |* T k! ^: _; {. S
*addr = ~cnt;
3 |+ F0 j2 V( Y1 ~ }
( w! C& |9 a: Y0 M/ f! u3 N. s6 D( q9 T
addr = base;
) m( J) z$ [# l sync ();
2 o8 U' n6 N% V2 s0 @, _. u save = *addr;7 Z" ~% U' p( C9 f# A
sync ();! `* D) [5 w* M3 @. G4 F8 n3 v
*addr = 0;
F& {4 c+ M' Q6 Q" g$ n4 d, _$ Y& [- r2 [& V6 w) c$ `: A3 Z
sync ();
! @2 N. j# X2 F4 v/ V; t if ((val = *addr) != 0) {
5 a1 x3 y9 L- ^/ V0 j /* Restore the original data before leaving the function.8 g8 @) g7 Y) b6 s! L9 \
*/
1 p4 y( r7 W" x) ?1 [' F sync ();
. o) h# `. V$ X$ O2 c( @% M *addr = save;
" l3 O2 Z* ` l2 S for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {5 ]4 H$ z4 {3 r1 l( c* K* n
addr = base + cnt;
. s2 _; L# }( `" E$ ? sync ();
7 k& r- A+ p: O m *addr = save[--i];
, n+ y# [) B5 b! [4 a }$ S6 y% |: c5 } x/ x
return (0);
- p0 Z( P2 j( e K5 X" e9 ~* T5 r }
, [! i2 K/ V n& u% n
0 Q! N- Y9 q, Q( [ for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {' E7 ]% h- I; ]6 b
addr = base + cnt; /* pointer arith! */
Q( `+ v! L8 w _2 P/ Q val = *addr;- E3 U) m5 H, N0 E7 l
*addr = save[--i];+ }7 I9 ^( D1 S0 ]) A; i: j
if (val != ~cnt) {; y" b1 Z3 Y( v4 @; U
size = cnt * sizeof (long);
" b& Q( u |$ U- J /* Restore the original data before leaving the function.! |) I9 Q. f# x
*/, _. Q4 M0 m1 C: r7 W
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
: Q0 u2 m7 @3 ~" c3 i addr = base + cnt;
% O! b* q; T; W, b! b *addr = save[--i];
' | |, L- }- | T }6 E f4 L# e1 y. {
return (size);
* K! @9 {# j/ h2 T8 J7 N }, R. Y2 ]- ?5 ]! Y" P, m6 T
}
2 D$ g5 Q$ r1 }% ^% s, J' J: k5 T, S" ?) f* o* K
return (maxsize);% d: J) w# P& T- T3 F3 \, ^6 e3 Q7 w
}
2 j1 T b- ] g7 g2 Dint dram_init(void), ^ }- z3 I- Z q! W+ A
{$ m2 F2 E [7 }
/* dram_init must store complete ramsize in gd->ram_size */
$ N; s5 E* X, `& t" _# J gd->ram_size = get_ram_size(
% i5 A3 ~! a4 s1 d. ?2 y$ d (void *)CONFIG_SYS_SDRAM_BASE,
, z7 a9 s6 f" s4 l" u5 C8 ] CONFIG_MAX_RAM_BANK_SIZE);
. z4 o+ m2 @" {) [+ d/ [2 n return 0;8 }" {# i3 ]0 @! k' X2 V) h1 x. j
}
$ A2 A0 z6 d2 j8 `. o, g" g" E" |; O* ?/ K( F' P
& g, }8 s3 ?; Q1 L
4 T3 x2 i; ^9 e" X2 y+ m6 {2 O0 ?' ]/ d( d
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
- L& F2 K- _( ^5 ~) x
6 I* {/ o; ^4 p/ U+ j& Z" o! D4 Y y% m% C& D
2 J2 T/ x1 O% N, c* ]( X
|
|