|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
9 |6 j( [4 x% C& K, t/*
J) Q9 s% q7 m/ b( `' f* Check memory range for valid RAM. A simple memory test determines
: \8 x3 {) y9 V* the actually available RAM size between addresses `base' and
: s: C& d2 }* r: [6 E* `base + maxsize'.
+ p$ D e5 Z$ i, h*/
$ \3 C% T8 y, w- V: q5 flong get_ram_size(long *base, long maxsize)" D! R$ ]& }/ t& |/ S3 l4 T& T
{
3 \- g6 D% W" f5 ^7 n+ V volatile long *addr;
2 |2 H( `5 a1 {# _8 u2 n long save[32];1 d! L- s4 h/ `4 ?/ O/ e1 s
long cnt;
& k2 d+ f$ o" U1 s, e long val;
0 Y# T/ S1 x! H( k# j5 k" ^6 w9 n long size;- f) G0 {2 y2 p8 q, l
int i = 0;
& y$ c2 O- X8 n) K7 G# A# C
. z$ S5 c6 R& b2 B8 ^/ {3 ? for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
, A! c1 ^, ~6 t, U/ D addr = base + cnt; /* pointer arith! */, ^2 I5 i+ V8 m+ X2 o
sync ();2 m L6 A# z( u o9 _
save[i++] = *addr;
2 m) H, v A6 o8 j {2 B3 W% k( ?' b sync ();
~ r: z' f! Z5 G6 x$ n *addr = ~cnt;: ]$ Q$ C* T" z6 S' y9 u/ H
}: y* @* [8 R, I: Q- U
1 l/ F9 i* T( H4 Z. w4 W addr = base;9 w5 ^' q! ^6 G, O
sync ();
7 e) s/ S: u7 k0 _7 t0 g save = *addr;
! R6 r+ W4 e- M' a& D( l& i sync ();
/ D/ ]# u! {) R% d) h& [1 X *addr = 0;/ H3 \8 C- m1 ^% U' L# u
& q; t j: \2 U. \ sync ();
$ _: _+ I! {4 k9 z# q/ Z, h if ((val = *addr) != 0) {
) s; U: ?, y7 M( F$ } /* Restore the original data before leaving the function.
1 @2 U( ^8 H% j+ T */
' H6 X o t/ ]* Q, t" [. r sync ();
: c" j7 j4 {7 ~, k *addr = save;' |2 n" Y- E/ F; x% ^
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {' G" U, ?7 _) c
addr = base + cnt;* Q+ H8 n! e5 i* x( n1 |
sync ();" T1 x0 w2 P$ q8 M2 l& Z
*addr = save[--i];' p: t2 m+ n0 g( E1 y/ t' [
}3 W% Z. ~ C8 W
return (0);) \/ i2 w+ b& ]9 v; y
}0 W" F, X) W; A. e. I9 F: k* Y+ O
8 E3 O8 Q, g- z2 Q0 P6 U
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
4 @& @7 [9 X, T% S: ?& `) ? addr = base + cnt; /* pointer arith! */
& k/ P3 ~& \6 f/ R# \, | val = *addr;* @6 \/ f; D) ?$ V w6 p
*addr = save[--i];; N+ i8 W+ T/ m0 O
if (val != ~cnt) {3 Y+ ?: }' |: z
size = cnt * sizeof (long);% h0 i" k6 I$ f, u6 |
/* Restore the original data before leaving the function.
0 a- l. }; w1 h) L/ n8 z8 s */
5 B. J$ y% ^2 A7 ?2 { for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
. u( x: r- a. I* a0 T addr = base + cnt;
0 |) y( J& h# Z5 I* _3 d& v) n: s *addr = save[--i];! D. v4 g% t3 w+ v* w6 [
}
; j) d# s/ G: S/ X return (size);
+ u) q) a# t2 ~& f }$ t5 }/ y$ f" A/ @" C
}, z0 G& I M3 j
: ^$ W+ _0 ? K- w6 j4 D
return (maxsize);
* O- y9 H# ?/ r2 W& m2 ?3 \, O/ @}7 e" {3 y9 @' O( L* L8 L+ x
int dram_init(void), r. y7 _! W$ g$ s
{( F# R5 m# V+ v4 f, v8 h: \ ^
/* dram_init must store complete ramsize in gd->ram_size */3 V; o6 o/ Z3 v5 o$ P& d& Y
gd->ram_size = get_ram_size($ B- M! S; F- U
(void *)CONFIG_SYS_SDRAM_BASE,1 g6 \9 X5 }) X1 Y
CONFIG_MAX_RAM_BANK_SIZE);% R% w* y' ]* p* p6 f
return 0;2 t* g8 }( Y" R+ K7 A* j
}$ U+ C0 T) i+ [7 [2 f& l
- X! E7 ]& F& ~: M) e# f( G6 Z2 e+ l* q1 @3 e6 m( H
& h3 Q2 T) b y4 s" c7 q, L, d
& i9 `5 p7 C" \# W' zFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
. f3 l9 {# h% z( i2 A1 L! ?
' ~( }" p( I8 o& Z# L* H* }9 T( i C$ ~0 g' g0 S; L) Q/ L
$ M7 F3 |/ j3 h3 C
|
|