|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
+ g( w6 m) }. n5 n3 `/ S/*
: w1 {% `: {' ^ M9 E, d* Check memory range for valid RAM. A simple memory test determines
2 R4 C1 O/ s) W* the actually available RAM size between addresses `base' and3 A6 @! U0 T$ X( H
* `base + maxsize'.1 U/ {& U6 _, ~4 [ f
*/ M/ }0 t/ g+ ]4 ^+ K! Q9 {! U, t
long get_ram_size(long *base, long maxsize); {8 b; Z3 K0 `( j
{- t: S8 K0 L$ |
volatile long *addr;
. e$ L1 L& h- ? \& R" {: m long save[32];2 S; C- Y; I+ w" T
long cnt;
. B) `+ G n* Q: B0 T long val;; C% J' r+ @" Q
long size;
8 h* ^1 H' Z" Y! |. v int i = 0;# l" \; d$ J5 H8 @
L1 d/ K- i) F; i
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
( W. z6 Y, b: E addr = base + cnt; /* pointer arith! */
) s2 }) r1 n& o5 U1 A; `* W+ D- Q sync ();( |* g% L( H) X5 f7 L7 @2 m& x
save[i++] = *addr;
7 }+ O- V J' S) V2 s4 }. s' q, h sync ();
8 l4 I% V4 y, D! u *addr = ~cnt;8 w u3 k; l9 m* C' W
}3 V6 l- ~* R! }
0 K2 y, M: B# H( m
addr = base;
( ? K. {" R: \ sync ();+ l# E3 s, U9 w( @: l6 X
save = *addr;' {; B) a) f+ J" G' i
sync ();
: Y; K: e8 r) a* ~3 V# y6 f9 Q *addr = 0;
" @! u u( V6 \: \! W* g" V4 A$ B0 T% A' C
sync ();9 B) O$ Z: p7 S; \* Z, p; Y2 f: b
if ((val = *addr) != 0) {' G3 {* R/ O/ J- `3 Q) u( ^
/* Restore the original data before leaving the function.
1 j! W2 A0 ~" o% d */
; o1 K) W0 m3 ~ k sync ();
* R; E6 N3 T8 u% }( c3 [$ v9 ?( V; M$ F *addr = save;, v3 s3 h8 e4 l& l T
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
9 i- X# f5 \" \ addr = base + cnt;8 w( |8 c+ }8 {: r: w
sync ();: u5 ~; f. S" ]- ], u+ |$ f
*addr = save[--i];1 K- d/ d+ k6 `9 O3 }4 P& X- A1 C
}& r; d; q. K' `) {2 u1 Q( L
return (0);) V) q- L: [$ D) o$ w$ f
}
/ M4 I5 F& L# K) I D% S
E, D% g& s; _" G2 N( O+ \9 t for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
: R$ u# L( K% y% o6 ^ addr = base + cnt; /* pointer arith! */
" k, y* z0 o- H! Q8 k/ x; V val = *addr;
- p* m3 f P6 H1 Z- K9 y4 g *addr = save[--i];" {6 M$ K6 F* g' R' n
if (val != ~cnt) {
/ ^% \$ x" \& Z$ n, K+ [ size = cnt * sizeof (long);' {, h2 b$ G- j. F) S- `3 j
/* Restore the original data before leaving the function.
. |. j2 w. f4 c, |5 r */* c- y' d* U" y- `; I
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
% Z7 c( B" x/ Q8 _( Z* p5 K1 V/ B: M- ? addr = base + cnt;% c: i" _$ c0 w0 t
*addr = save[--i];2 R7 O# s9 h' b& d
}. f! @" w0 U2 a" c8 m' V8 W9 m- N
return (size);
3 G) u: M y4 `3 j7 v4 J6 E* w }
0 H2 C! P1 J) Z( C" Z% I: \ }6 n+ {1 a: u+ T" E
1 ?" u2 b0 o& ?/ Y! H return (maxsize);
8 x' z4 S, o0 q; z}6 k) d! p' s- o$ ~2 ~
int dram_init(void)
1 |5 w+ S/ r- @4 z# @( Q{
7 c8 V. O$ y; M8 \5 G4 D /* dram_init must store complete ramsize in gd->ram_size */
. f! |7 T- g; M8 _% u gd->ram_size = get_ram_size(
. W/ t( |7 w; F w5 H- P, @/ |* G (void *)CONFIG_SYS_SDRAM_BASE,
$ n; h5 o" L& h5 N6 V2 V( c& A X. q CONFIG_MAX_RAM_BANK_SIZE);
4 r: c$ d- b. c1 s return 0;
' @+ q; d7 L# T; t/ E: p( s}
( ~( B8 J. U( D4 @" f) ?8 [- @9 w) h: A1 f4 A) `7 B
6 s! I; O4 W" A8 Q% k/ w
9 M) F6 Z" Y8 \7 F3 J4 b% n5 }) d% d
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!; _- P% S. l: Q( o: i! G! T. q
`9 _" W5 b I3 V
J+ X B X# A( P4 \$ ~: z% Z' [- _9 W: @2 n
|
|