|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:& `' d! M* {/ o* Q0 p; r6 J3 {
/*+ u- B0 ^( \3 b/ c7 |
* Check memory range for valid RAM. A simple memory test determines
$ w' j$ B6 q- O. [/ \: _ j* the actually available RAM size between addresses `base' and; m7 l5 ]/ e2 W# K( w
* `base + maxsize'.5 v8 z( K8 N& b
*/; i; C* q9 D A' R3 ]/ a
long get_ram_size(long *base, long maxsize)
5 {- P* z8 ^5 j2 i{
7 V+ m- @- |$ c0 _% e volatile long *addr;* Y, ~2 j. ?& F! m( `) {" t' T
long save[32];
3 \$ V) J- `# C' n# ]" c long cnt; S I/ u8 V$ M) E
long val;+ Y9 d* V7 N* Q1 E$ G/ p
long size;
2 a' V9 L9 A( p5 G+ u ~. l* I% s int i = 0; R R* z( _) ^: W) O6 @/ @
! V. n" [9 `( A' X% R. X$ y for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) { }3 d+ u8 m0 n
addr = base + cnt; /* pointer arith! */. `4 r6 ?% }0 C" c. c
sync ();" v) e& T& H+ o/ {3 e' G
save[i++] = *addr;
7 e- t7 E& M7 ]8 h/ K# |! ]4 @ sync ();% q1 w2 w0 i* o. T
*addr = ~cnt;. C0 r' x( X- F: l+ m
}6 P2 E3 x! V: L, T
6 A% g1 d) ~6 ]4 U* O; c
addr = base;
n# ?2 s# o' E, r7 i sync ();
) c( F, `; Q8 m( q- m$ S" ^) A2 w save = *addr;0 `! @0 u2 n$ l1 B) P
sync ();+ m3 }( ~4 X: s( @
*addr = 0;
2 h5 v9 n. f* V2 T; D; a* t% E( h; i0 I8 X
sync ();
2 Q6 i; w P2 L8 K1 w$ [0 F if ((val = *addr) != 0) {
8 G& T; X' S8 E, R1 u /* Restore the original data before leaving the function./ |; ?( m: L/ {' v
*/
1 a, H2 K& `1 o sync ();
5 s+ t4 d' m( @2 m; A *addr = save;
3 Q0 Z. C: r2 Q9 { for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {( H% W( p! l$ `4 U/ Y, H' q
addr = base + cnt;* J4 V7 e# j. C. y+ E/ V1 [5 l
sync ();6 b$ d+ k4 z, f) t. T0 ~3 \
*addr = save[--i];
6 Z+ F7 s! D; t }- V& }, n! m- Q1 x. N$ a; U
return (0);
8 J, b' {3 h/ [$ H }. K2 _! p4 n- [* g) @0 K( Q' R. \* L
5 ]& l5 Q$ h) m% j2 | z7 u( g3 @ for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
7 ]+ i4 T3 O! L1 t4 H addr = base + cnt; /* pointer arith! */$ L, p( G# C, Z3 L7 z! a9 u1 a
val = *addr;
5 g* e/ U. H k: Q( V *addr = save[--i];$ L t% O( v; E, G4 |
if (val != ~cnt) {
0 G! [% M q2 W( J& L! y# J% q size = cnt * sizeof (long);" q1 ^2 K- I+ D+ @' a/ x6 i% C
/* Restore the original data before leaving the function.
8 x8 g5 B* F" K! `' f4 [ */
6 l; F8 ~. ?. e* s% {! x for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
8 J8 @' Q8 q! r# U* f6 m- q addr = base + cnt;( F1 L! ~( D. W' m1 g* ?
*addr = save[--i];
6 p1 l6 n. L/ a* O8 ] }
. J5 e# k/ b* G7 v return (size);
0 h2 r4 y9 ?- ` T. r }- e6 k `1 C: g: X
}
' i3 x4 p6 i/ C# i% ^
! R7 Z* b4 @. O$ M t- w. }0 G W$ z return (maxsize);
" O7 ^0 i% O0 f% D: |8 f}' }# U [/ Y5 w
int dram_init(void), R$ S6 y3 x5 ]. B; [
{
5 G! t& E4 k N/ v /* dram_init must store complete ramsize in gd->ram_size */
8 m# l* d2 ~; E6 I9 q& _* |8 A gd->ram_size = get_ram_size(
% d: D: f- B5 h+ A$ M& d. H) J (void *)CONFIG_SYS_SDRAM_BASE,
' t# t# J: Q: ]3 N5 u CONFIG_MAX_RAM_BANK_SIZE);
0 {6 M* c: ]$ h6 S, R! W return 0;- u% w$ @2 A c% Y+ [0 A
}
7 N+ b0 s( f" s0 f
, h) y3 |# Y* i7 b# d9 o% |3 B6 h: G6 i3 S
# H) Y' `6 }6 i5 i- A; Y
' v7 [4 e# l+ E$ w7 J, X
) T' Y0 @! ~+ D& H; n, KFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!$ I* O& w: Z& ~ U
8 s' j# F. V6 F0 }( A
4 E' L$ b9 m7 Q
" X- s" w- m3 q( p4 p
|
|