|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:4 C5 T) p2 R% L' P; y
/*
, i$ i9 H% [. K+ \" ^: p+ c- t" |3 H% q* Check memory range for valid RAM. A simple memory test determines2 m) P& T! S: U! S# F+ d
* the actually available RAM size between addresses `base' and
. F# V4 v( Y- W: k. s* `base + maxsize'.9 d8 P$ M. i) S
*/
# C5 q& @4 c0 q9 c7 Ilong get_ram_size(long *base, long maxsize)
: z" ^1 ]7 |6 y" ]{
8 O0 f8 n4 L# z M volatile long *addr;1 J8 J0 ~) j- H. o& o
long save[32];7 e4 _* ]/ `# T& c( j. P
long cnt;5 y' Y' Z' W( o: H1 v
long val;
* k8 ]- L1 h6 L. C" W+ I long size;6 o4 Y# o# }9 g: G! U4 u' W* H
int i = 0;
! f6 `2 V% G3 r. O H) \
( v+ l8 Q: G! Z* l! m5 r6 j for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
- r9 G4 J# K0 M. Z- o9 t addr = base + cnt; /* pointer arith! */8 ]: r2 o2 j G$ R
sync ();
3 ?* }! m9 t( n/ }: h3 e3 S save[i++] = *addr;' q1 M" @% x5 [5 e1 m. O
sync ();
+ a/ v+ x' g. p% O *addr = ~cnt;4 g. E6 g+ o( F4 C& { U, z; L" J6 d
}
* N6 ^- g4 _% e1 E* J/ C7 n$ B4 ^* u, B3 z8 E' F
addr = base;5 b: a- B7 c1 y& H# j0 s" l9 B
sync ();
! K: F* e+ s2 v$ } H! U save = *addr;6 f/ v7 R% a% P
sync ();
7 E- ?# j! x5 s$ Z4 {$ v0 c *addr = 0;# Y5 }/ R( ^" Y
& f* p0 b5 w' ?: f; T8 S sync ();
( |; D5 p: Y, w3 T( V5 T# W if ((val = *addr) != 0) {1 t* s; {2 y& O5 r ^$ T
/* Restore the original data before leaving the function.( c6 Q9 h+ g3 |' N2 X1 _+ K
*/
! \; m" q) j- m sync ();
w2 Q0 P* c" r/ U! [ *addr = save;
; I& _/ E6 z) j3 g, ` for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
0 n' C( d2 w- m, J: Y- L1 N addr = base + cnt;
2 m- k3 Y: F# {% C& [% n0 V sync ();
9 N! [ K1 Q7 Z7 f$ r5 s8 i *addr = save[--i];% p5 Z1 \+ P" j1 y! L( Q% v5 y
}( x5 i7 S" p1 S) M
return (0);! \* o1 [' X" B2 Q) ^
}
8 o8 j. M. E* i& U5 A) X4 O+ A, {4 c
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {+ p/ l/ u5 q& \0 ?4 v6 u7 T
addr = base + cnt; /* pointer arith! */
6 k# j4 m P: I) |4 L val = *addr;
6 U* @7 b" o4 ^$ b' A7 ^0 u Q *addr = save[--i];
, s' Z% k$ {2 E: Z( |: N0 O if (val != ~cnt) {5 l7 E# V9 `) n
size = cnt * sizeof (long);
1 t, {5 W {; b6 F$ |0 A" A5 ?# Z /* Restore the original data before leaving the function.
$ b% J, p! d, M */0 S9 @2 A- j& d2 J/ [
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {# W7 b3 W9 D/ b& z% Z+ U$ _) V
addr = base + cnt;
* D0 C1 F! x" B9 Q+ I: |: i9 v *addr = save[--i];6 Y% L7 w' ?3 K& _
}: I9 z0 }( ~9 M! {! ?1 G2 b
return (size);
6 ]- P% b/ v0 K1 M; d }
+ a& d0 Z% ?! E$ @ d }; |' H5 n. l6 N1 _7 W
! U. u: N( A& `( G
return (maxsize);
9 R& W3 Q" ~! W}" }7 _' \$ U# }0 @' s7 r
int dram_init(void)
( J' b7 s8 P4 k0 p5 }% f{+ _" |$ @4 p! Y) Y( @; Q
/* dram_init must store complete ramsize in gd->ram_size */' v0 i- d* E6 M9 E! R! O
gd->ram_size = get_ram_size(7 K" c( P3 z; j& b" c
(void *)CONFIG_SYS_SDRAM_BASE,' O+ H$ B6 p- I7 H, L
CONFIG_MAX_RAM_BANK_SIZE);; B: ^! Q# {7 a& d" j' k
return 0;
& O% w% m& @. `- U* ]9 H B}
# e1 S3 D8 V I! ?- ^: K7 t" ?, C5 W
% \6 ]+ g" v# [4 s( C+ z9 P
" F4 c. ?: i5 ?3 Z# v! l- J9 i- C4 M3 d. K6 l- u9 t
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!& n {1 Z# k. ?; y' Z I8 J
* |+ l7 l) j& B* d$ v- y* y% B; g
) O# S+ Z1 |7 ^. K: Z
4 Q* N$ Y4 ^2 F# n: r |
|