|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:7 ? o5 t# w7 V) _( ~5 b
/*
6 c4 J8 O3 T; g6 }3 F" ^* Check memory range for valid RAM. A simple memory test determines( f6 O) w# ^8 c
* the actually available RAM size between addresses `base' and
) B6 o& m. b7 r1 {" d1 M4 ?* `base + maxsize'.0 `1 v4 w a- B
*/2 i% n9 D F7 [7 f+ B2 z$ Y+ g. N7 q
long get_ram_size(long *base, long maxsize)
, U9 ]& ]- g$ Q. a4 N3 W{* o+ j6 X$ G- s* _; m- @- A
volatile long *addr;
$ I8 f- e" q* j( g long save[32];* S6 n7 \$ s. |. m
long cnt;5 z P* [, `1 x0 q, y$ e
long val;( v4 v: j8 a; X5 {6 Q
long size;
3 I3 x+ H, \! `. u# q3 S int i = 0;
" }, L* x8 F6 e7 L0 M5 I3 s
+ M& [ y' W% Y+ i for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
: s! W) e) `, ]! d- U/ t addr = base + cnt; /* pointer arith! */: j5 y# R$ O( Z
sync (); l& c( n+ J" O7 c/ p, i
save[i++] = *addr;0 f( l. d7 J) |
sync ();
6 A/ x/ _4 `, J2 ?1 X *addr = ~cnt;
3 A" g4 j* _8 T5 @; b q }
. d# f3 w# h( f9 y8 ^# q# o; k
addr = base;% J/ q. X1 v6 [" O
sync ();9 F" o/ B2 K6 T7 j% p) X
save = *addr;, t/ b+ N" g& g( p* a+ I
sync ();0 I- K2 s8 `) V3 M# @( K
*addr = 0;3 w/ X. `6 C# T9 o6 {8 s* `
6 n/ I; X$ F6 E c% W* n
sync ();& m! u; A2 A8 D: S& Y! ?" u
if ((val = *addr) != 0) {* u5 P& {$ V3 n: P9 A" Z: i
/* Restore the original data before leaving the function. N, v; u$ R/ I' z. ^: D0 \
*/
# c' F5 q8 G9 W% v" x% H# m sync ();( l( h( V1 W3 H2 d4 a
*addr = save;$ w; f8 }7 G* M( ^ ^& Y" Y9 F
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {$ R' w5 y+ L6 U
addr = base + cnt;- M% I" A& k! i7 Q, N4 C
sync ();
9 S% V( \- n) {+ y3 v1 Z *addr = save[--i];
+ P* W& @# D3 Q1 K+ M# j6 B( s& q }
0 C1 b! L" T7 K W return (0);
* Q4 F* W9 p" [$ n6 K! y, [ }
% H* q3 ^4 i( W+ a% {+ Q
& X# h3 d7 L/ y- J0 V for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
( f* X* ~$ _$ j6 A* R% U addr = base + cnt; /* pointer arith! */
2 q2 F4 F7 T V1 d, {3 a val = *addr;
7 x- L1 ]3 M0 u* E2 X8 _0 T *addr = save[--i];3 Z; R3 x- d, M- y3 r) J1 N% H
if (val != ~cnt) {# z4 d& q0 r& y8 A
size = cnt * sizeof (long);
. x! R3 z: Y1 ^; h /* Restore the original data before leaving the function., G& m: ]# _* R# A A
*/8 b( q+ h9 P, A* f
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {# X2 \. ]) {+ E2 j4 N$ N6 [
addr = base + cnt;
& T& [# _ _/ l2 m7 E *addr = save[--i];; ? [, u j8 b. d+ F- C9 s
}8 k g4 q; u, |) r7 u# H
return (size);' }+ ]' a' Z; E0 Q+ X. T1 X
}! U: i# [' f- R4 H! F5 O
}
# `4 j/ Q; N6 v( L. w$ m4 J2 s1 P9 I, N# `
return (maxsize);
; ?' |2 v3 R; c M8 Y ^}
, B# D. E6 y, y. T$ D; yint dram_init(void)
# t* w1 ~7 F( J( O i' i% r{
( s0 R% i) G$ c! S& S6 A /* dram_init must store complete ramsize in gd->ram_size */" L( P8 _7 y% v# q. c8 K/ B- y5 Z
gd->ram_size = get_ram_size(
8 L N( M W/ Z: X( L! R/ u! S$ w* k (void *)CONFIG_SYS_SDRAM_BASE,
0 W( M6 n/ w7 f2 x5 m CONFIG_MAX_RAM_BANK_SIZE);
0 i8 k% C. L7 Z2 u: C* R; d' y" o return 0;& i% |( S- u, r1 h- i8 X6 T
}
" b: `; S1 b# ?( j- x
$ x1 }% i8 e3 Y# d5 Z x! V9 b2 K2 v! I: {/ b; _0 t* H6 m- d$ ?. e
, i$ t3 H! F5 ~. l; y0 ~
" M3 k- L4 @, d( k9 ~FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!: G: \! j# b4 @' |0 F* V2 B& D0 X
9 O4 j' H7 \4 P2 e' d; [/ g: n6 O% w+ I7 u6 V
: S7 J4 R9 d- r0 _: s2 n! S6 a
|
|