|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:2 y* I) I2 \4 i; T
/*5 X$ I- p8 P* \5 e/ W+ y9 }
* Check memory range for valid RAM. A simple memory test determines
- @3 }; K5 J* S [5 t6 n* the actually available RAM size between addresses `base' and
* p' }' }, w% h! \* `base + maxsize'./ d. c& H" u* ]- }8 V# h
*/6 L+ S# }- F% Z# @& m* P7 ?
long get_ram_size(long *base, long maxsize)) ~6 J8 L% b* W# A) M7 u
{, u. x2 d) [- W
volatile long *addr;
2 v4 Y* p# r r, w! u; Y long save[32];! ~! N$ ^9 d2 Z
long cnt;0 R' @1 D( M+ [) G
long val;
% e0 p0 ~" y Y7 X" T9 r long size;
! A, s F5 [( p- j; y int i = 0;2 x3 S" D0 L$ z4 D" ]
& u- t0 z9 d/ N& K7 u
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
3 ]1 S. r) t6 s. I4 l Y addr = base + cnt; /* pointer arith! */
( e8 |1 ~+ g4 H1 y sync ();
" _" Z+ E* D7 Y [3 O+ C save[i++] = *addr;* K$ z2 u( ^+ s J% ~
sync ();
# |& B4 y, e7 N d9 o) ^, P *addr = ~cnt;
6 q6 M. N4 W; P4 J }+ [, K& K7 F# A: \3 ~) I* x
) x" `4 |9 |# ~ addr = base;4 C8 z& [0 U0 Y' H: j; F9 c; @
sync ();
$ i/ l; b/ `! { save = *addr;
. W1 d; U8 |" f0 {6 c. T# Z' Q sync ();3 n' K! M- A" v$ W- r5 U
*addr = 0;
5 z; B0 n1 K0 p2 W2 m5 L) T0 }1 e& S! K* @4 l) n% v$ n
sync ();
. I5 B$ v [. V if ((val = *addr) != 0) { o4 r. I4 p# u. \
/* Restore the original data before leaving the function.; `, O1 Q3 ~7 Q
*/! v* ]) j& b% B8 x4 i5 N
sync ();+ S( A- D- \' @$ D
*addr = save;
& C; Y8 _. Q* Q: C$ w" T' n f for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
9 s% e5 Q* `) _ addr = base + cnt;3 r6 R5 j O, P
sync ();
+ d2 y4 ~& p3 c5 ~5 v5 r( p *addr = save[--i];
- c2 \* D8 C; { }5 a9 b' m; v' i
return (0);
# [/ w# w" ?* K7 V$ l {4 Y4 Q }. L4 j5 t( Y" } s& }
" i3 f$ s) H, m0 u/ U: W
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
7 I% M1 M: c( ^4 M- C* _% f addr = base + cnt; /* pointer arith! */
( R/ _1 j0 l6 a% ^, ]' B val = *addr;8 {- L l) m# p) R; _9 V
*addr = save[--i];
2 p" e) t; H$ M& | if (val != ~cnt) {
' r: K3 ^7 x J size = cnt * sizeof (long);; j+ n2 ^9 j8 | l6 T( H6 N
/* Restore the original data before leaving the function., W& Q, l2 N P0 d
*/
! ]$ T3 j6 W" z for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {: L* T" P3 b: \4 v
addr = base + cnt;
4 H* [9 n% u& l- N- u: F2 A" T *addr = save[--i];
! y- g$ q' [' G: F } U" ~' u! X* k" I2 A- h# C
return (size);
. I6 }& J. ~0 @$ j1 u6 D' L }% g, I0 \2 H* e
}
4 A, S5 ~! Q6 L" w" ^! l6 ` M" m
6 g a% p# Z4 s return (maxsize);
% M9 D7 h( t3 B% S}
' |. l3 l7 |( G9 T3 I) Cint dram_init(void)! z D. w. F' D7 u3 M+ b x5 M/ b
{
. M" v0 Z2 [& l* U /* dram_init must store complete ramsize in gd->ram_size */
0 s4 R, V; ? q8 ?6 p& N gd->ram_size = get_ram_size(
' G; `: P* P! \0 d+ C/ E (void *)CONFIG_SYS_SDRAM_BASE,
6 z4 l- K- q/ r CONFIG_MAX_RAM_BANK_SIZE);$ X6 s2 K- `$ M( R p, Q5 o {
return 0;
2 K Z8 x' W* ^( c1 \- S}
. r$ b) s. @7 J$ _# z" D% e( x" n) H% ^7 F% B
/ O, G+ j- n% T7 a, @6 |0 D; p
- g- e1 x9 ?, Z" N2 D4 U7 q5 k1 Z
) G0 r! @3 n# ?# Q" mFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
7 R* n. m% U) l; e; b9 M* `: x' j5 e2 i3 p' o$ k
6 O; f" _* ~" b! L8 H5 g
5 V$ I3 S. `; y |
|