|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
$ {& {+ d3 f- o1 X/*
, t' S7 f" V* n. |* Check memory range for valid RAM. A simple memory test determines4 | C8 I! H" n; @
* the actually available RAM size between addresses `base' and
4 M7 Y/ V/ |: c' N* `base + maxsize'.
* [' L9 I2 K2 ]6 d' Q( L*/) B3 W1 S% o6 F$ Y6 z7 o5 Y
long get_ram_size(long *base, long maxsize)2 x% j: O, ]+ S& r+ m# m$ k
{1 h" k k6 b0 R& b
volatile long *addr;
) m8 ]$ Z# r' ? long save[32];) N( d; O7 G6 o- s5 z. r# u; i
long cnt;
( d6 {) L S5 Y7 \1 t long val;: O- S" q- |5 L$ q" v
long size;
a: d' e$ R# r, Q0 l int i = 0;& ]$ |- h$ S$ L9 x
0 i4 @1 j3 J2 ?/ c% A
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {! `% \& f V" s4 F
addr = base + cnt; /* pointer arith! */3 o9 K& W, b) ^1 n6 ]' k$ ^
sync ();; j# \& G: t) a
save[i++] = *addr;% X6 G! {% y& A
sync ();
# w, r$ @$ f, \% A+ z *addr = ~cnt;
7 @& J5 N( T) V" i/ N2 y }
( c) f( b+ t) k: H7 U8 q( H' R8 {* P. z4 m/ `
addr = base;
7 C) e+ W/ A1 A5 H- p! D" q w- y sync ();0 Y# ^$ r7 b: e3 Y' [+ s: E; B) y
save = *addr;
5 m2 G$ i! l, y sync ();
; R! T" m3 G) M o) p6 J+ d *addr = 0;2 [( ~) g' [3 i
4 A' e- c8 K5 g+ U
sync ();
8 R" \9 L; V3 q if ((val = *addr) != 0) {' X+ L/ X: W' f8 R
/* Restore the original data before leaving the function.6 Y0 I# l3 Z7 F5 |. u- T3 \
*/; j( {' q) Y0 @# L& l' x& }8 P3 C
sync ();
) ^, f+ w# F( x7 s+ W) C' P *addr = save;
3 d6 O; N. H3 s" T) w for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {# C# f9 {- d1 \
addr = base + cnt;+ Z( B; r9 \6 F. v' _. d
sync ();2 o5 ]$ T+ ?6 y- a0 \
*addr = save[--i];
) G" F" ~0 P! e, T! s8 ~* x }6 G& ?4 q; }( F- B) ?
return (0);# q, Y9 I! S& n& ^8 T
}: k! O- O4 E4 q; C
( H/ B; o: T+ S2 ]4 a
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
- k5 {, s8 e+ x6 }# ?" k( i9 S0 c# _/ | addr = base + cnt; /* pointer arith! */- u, m5 |* ?$ b1 P
val = *addr;
( b" g' F' C5 b5 c$ V( Q *addr = save[--i];4 F/ u K- c0 z8 i: x8 n( {
if (val != ~cnt) {
9 q; k- k. s9 L* o0 y3 v# K" M size = cnt * sizeof (long);0 a: R) Y6 {* K( `4 k
/* Restore the original data before leaving the function.; f3 Y0 Y, @* \! }: K3 e' @
*/) ]& A$ L# z: P5 t
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {% a. O2 [3 v, W% y- w
addr = base + cnt;( N* Q. p' V/ t& z( }( m% m
*addr = save[--i];6 e% N) `+ Q7 x, R
}
; N, A/ V4 r1 g, i! y return (size);0 v2 |8 g# l2 u; s! E
}
8 {% |) m9 `2 Y h% x }# S! m, k: h# ~: {4 ]* R d; O
* i; }# O" y; e A; r
return (maxsize);2 G7 V& j \: u( l5 S4 I7 k
}' |! c, O4 f* U2 p$ d/ {
int dram_init(void)' P: ?; I/ R; N: a4 L
{
& P6 I3 D1 N/ U9 c /* dram_init must store complete ramsize in gd->ram_size */
' A- |- c1 Z5 W, _+ j1 C gd->ram_size = get_ram_size(0 F0 g2 a4 z7 C
(void *)CONFIG_SYS_SDRAM_BASE,
p: D% X1 H' k0 u# S8 b9 z9 K2 T CONFIG_MAX_RAM_BANK_SIZE);
. S8 `' L! T3 S, ~6 r; l return 0;
3 z: p4 _5 x$ g}
( ^# O `1 h- F* n6 h6 b2 w7 M p* s! g7 W, `2 n, v& \
! w$ W- Q4 Y! {6 X8 {8 t& `4 Z1 D$ {9 K$ W8 j
) p9 [/ v/ }- D2 R) F7 O* R3 u/ Q
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!5 U0 G# w* X% O/ i
9 Z7 u" Y5 p- y d7 {% [4 \( C& C
# i/ M4 x8 D4 Q/ x. P |
|