|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:8 A& R6 d A2 F% @/ V
/*
# n, C5 H( m; _1 E: A* Check memory range for valid RAM. A simple memory test determines
2 W3 E- J- o u7 q( C6 Q* the actually available RAM size between addresses `base' and
( V, t3 P+ S% w9 m5 M3 B6 Y* `base + maxsize'.+ J5 f5 i+ y, v$ t# C8 P# W: c. V
*/
2 l9 U- r: b+ n" X8 R8 e: wlong get_ram_size(long *base, long maxsize)
7 x9 g7 O, D$ K- h3 K( j. S{
) s) g4 a1 x- X volatile long *addr;% J6 T7 K h% i( G3 U1 N+ U _8 S
long save[32];* R( m% J0 W7 \) r: n) m( E( S( g
long cnt;, p' @, O! G) I' g
long val;
: l! d# o4 N& N5 t. @. ^ long size;
s3 w r) m( }9 t- @0 Y6 U. Z int i = 0;
. s& L0 r/ x1 W- U) e' q% A' c9 L5 G% l. w1 u, ^$ G2 x! T# w& S
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
# [5 z7 Z) ?- P& a7 N addr = base + cnt; /* pointer arith! */+ L7 W( q M j
sync ();3 F4 O2 C/ r1 [/ t1 N, ^! W. V
save[i++] = *addr;/ w7 I. u; [$ c6 D. c
sync ();
6 f# [ m/ G- b Y8 C0 r W$ u3 ? *addr = ~cnt;
" B' h8 v3 V8 f3 M' r }4 ~; ^+ U7 b) V
( e. K. s5 N( |6 r+ B addr = base;
H" k5 C2 x: Q" G6 s2 N( T sync ();
" Z( Z# V3 k+ c( n; R. k: I9 D save = *addr;
; Z4 q: i! y4 k. ~9 p3 ~ G sync ();3 G% [: @3 u. L: K: {9 s( B
*addr = 0;8 U1 a0 e# `$ g/ [6 j
- K) W& z( v! S0 \; m* E2 ~$ d6 o4 m
sync ();9 n) z ?; g0 O) R2 d
if ((val = *addr) != 0) {
5 Q7 D4 D% l Q, F% q8 ^/ |3 a& I /* Restore the original data before leaving the function., i5 X: D6 s2 v2 Q
*/% p$ v' N" W1 I( M' [; f! ^& m
sync ();
) f0 h& j' s- w( { *addr = save;9 e$ k# C/ r% y& l+ }* r, k; R
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
8 U, H2 d Y, J% ]1 b addr = base + cnt;
R8 d" F+ x# B# z. g9 Y sync ();, e9 A8 V( F! Q9 c
*addr = save[--i];' \; l+ ^4 J Z, N2 z$ E, i# V
}* }# w! {$ J# [ R5 G& A# a
return (0);) ^2 B N; g2 O" D& g7 s
}
s3 c% ?: P6 u0 F7 Q2 t6 e6 m S W6 b7 k; u+ U
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {5 C8 C5 Q6 z1 c; M. p2 K" X+ f4 B
addr = base + cnt; /* pointer arith! */
# ~ @- D8 ]$ ~3 D5 E7 a- b1 j' S val = *addr;
y. _1 `# E: J- h8 |0 Z *addr = save[--i];
5 n* z2 z4 x3 h if (val != ~cnt) {8 E4 q. Z4 [/ ^6 f( G# Q7 ~' A
size = cnt * sizeof (long);( o! ~: e0 x3 ]/ U
/* Restore the original data before leaving the function.
& U8 ^: f" m: j7 u( t8 D/ Z5 c9 ? */+ r, }- I5 y e4 k- h! e2 G+ t
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {' c7 |; W" k; W' t. k, H# } f
addr = base + cnt;
! X9 ?& c k. F- J R) l# O *addr = save[--i];
$ s% k! h, K" p+ q. j- @ }' T" t- V" q- y* d7 V3 Q3 e: |
return (size);
6 O. ]$ M' G3 e. M( C/ c/ `6 x }: `2 K& E9 Z% G; y# }4 N6 d
}0 S- u/ _) |+ d. _
: @( m* \/ T9 o* x5 N0 q( y
return (maxsize);0 `( Y6 u0 t: W$ y. k
}, a5 D9 g2 O* E' N" R: p8 M; i$ o
int dram_init(void)( T6 S4 s( }+ r6 @( w
{
' N. O) s! a6 v2 d) ^" W9 I /* dram_init must store complete ramsize in gd->ram_size */
# S6 P' _) @" J7 m7 Q gd->ram_size = get_ram_size(
: v- i; _$ {) U0 N& e (void *)CONFIG_SYS_SDRAM_BASE,; ]) i% L7 K9 g1 a+ [& \
CONFIG_MAX_RAM_BANK_SIZE);
1 c a2 h; t: V: d return 0;6 |' L- x! ]' G N2 ?
}* Y: v/ U! s8 ~1 b' V6 l0 E3 X5 r( f
. k! ~+ n' o5 W
4 J q7 Z6 d/ p/ I3 X! d
( `; @1 `' x, U" d/ a
( K4 |+ e; j+ Z
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
: Z& B- `: d: _& p0 R% k( M* N6 O2 n
6 x, W3 ` s4 r4 p
) ~7 `& q+ t2 o6 S |
|