|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:7 x4 ^4 c" S) J- a
/*
) G6 ?, j! S6 v- e* Check memory range for valid RAM. A simple memory test determines$ c7 Y5 o* V/ x2 z) Y* F+ v
* the actually available RAM size between addresses `base' and* [) b2 s- C+ r7 L9 x$ t8 t
* `base + maxsize'.9 K! c6 M- Z L' M% O
*/$ D- G) ~( ? a
long get_ram_size(long *base, long maxsize)
- b1 o! x. l# \7 {/ E. ~- }{
1 `0 B9 H2 J% s volatile long *addr;* {" S9 R9 n+ T" f* r! {
long save[32];2 @& j. Z3 ?5 W% H/ }
long cnt;3 y+ R# b; U( M9 _; I$ Y
long val;9 _, O6 B# o, ]* M u$ U1 C4 h
long size;
- G* N8 I; m$ \* n) W* ]' V4 P& } int i = 0;
. P! ]( l2 R3 I) y" ?$ J6 ^% B8 h& G9 i c- m
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
8 t+ P; K) M% ?% d9 a6 F/ j addr = base + cnt; /* pointer arith! */' w/ ^+ S5 \7 e5 J
sync ();6 x* m u; ~) L( c0 ~
save[i++] = *addr;7 ^ }: M: P3 T Q( Q
sync ();
) }3 i$ q+ U0 q5 y# R: Y$ W8 I *addr = ~cnt;) y. Q0 t2 w- L; O/ N
}
9 M5 L- ]" D" U8 u. P. I- @2 H/ Z' z, }- H4 \# t2 d
addr = base;1 Q' S0 t j, z* \0 v& b
sync ();
$ m5 A8 D7 c9 y. j" ]) h save = *addr;
, m5 r% C' W! ~; ^ sync ();
( `+ I |4 S! Q4 T! R *addr = 0;
4 A/ J* u$ E$ _* C
6 C# _/ K5 v5 K% O sync ();
4 I$ s- U$ r0 ?7 V if ((val = *addr) != 0) {
6 G" Y5 ^$ a2 v+ z /* Restore the original data before leaving the function.
- E/ l: d9 L# s' m% }1 `# F# X2 e */
6 Y: a8 a+ r0 h5 v# A. i sync ();
& {! r6 t& C% h5 X3 n; j0 @ *addr = save;
) k0 l$ C* s( T( ^6 | for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {$ a, t0 }9 ?; V( @8 x
addr = base + cnt;
7 I" X' }- O& d) T$ `1 G sync ();9 q- W. W7 N0 B* Y1 }9 s
*addr = save[--i];
, i# o2 ~% f& W5 m+ s }" j! `7 W) \3 j& B
return (0);
4 G& V+ y5 C0 a, M }& W f3 \0 d" u" E0 T) X9 p
3 }) s+ E" ?4 |) m! N4 T. D for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {/ ^- V" f+ c. K! p2 P; l; Q1 Y
addr = base + cnt; /* pointer arith! */
% {. g7 L0 ~ t$ d1 [ val = *addr;
3 @% V% M4 T) d! N' a: O *addr = save[--i];
: L/ K6 V+ P8 C, ?3 q+ A if (val != ~cnt) {# W2 {" w, Q( G4 \
size = cnt * sizeof (long);
6 ^, v. P# Z+ {/ C /* Restore the original data before leaving the function.
/ f+ Y$ g; j2 _9 w! c6 c2 f% Y- I */
3 r" j' O/ ^ s0 s6 B# I% g for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {; A& I* b; j0 | h, Z2 |
addr = base + cnt;
" `/ E4 W/ o/ ]( u! m *addr = save[--i];7 ], Z3 M6 f, R: I+ r
}3 [& }) O% m4 M6 G6 C9 c2 Z
return (size);7 ^" _' q& i$ T; P9 U' g" z, A0 `% L8 w
}* `1 j) y: [+ E' X
}) q9 i# ^ w2 e T# h1 k F
8 C) Q3 ?3 \3 b( J7 D' }" t* _
return (maxsize);; S* m0 ^2 u( q* a+ D
}
+ a5 _# A z: e: y$ Oint dram_init(void)
; |( t X) L e7 {4 a. k9 F{
# ^/ k0 G% L+ F# f* K /* dram_init must store complete ramsize in gd->ram_size */9 O8 }& E. _% x' ^9 N) _: X, {% c
gd->ram_size = get_ram_size(5 ^% u: e0 W/ B1 G8 `. _( m
(void *)CONFIG_SYS_SDRAM_BASE,
9 e. Y; E' j3 X" Q CONFIG_MAX_RAM_BANK_SIZE);( |! N" ?( B6 n0 m
return 0;; q: J2 @9 g2 `6 c- b4 d8 y! L+ X
}
2 ]4 \ x" M: S. X. l+ d/ g4 Y; C( V$ }: }7 x2 A% \; c1 S
5 {% ^$ k4 {) Q% o) d& b+ `; B* v; ~+ ]9 @5 y* |, E9 ?% |
0 a9 h% u6 U4 C. x: XFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
2 u. p. l; O$ C4 Z9 T
* H. ], s- n6 `4 g$ ?0 k2 k% b5 \, K" K O( C
1 u; u( i8 W5 N |
|