|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:5 t7 \' `/ S1 `. q7 o
/*
. f2 Q! H( [' Z9 Q* Check memory range for valid RAM. A simple memory test determines' O" G0 P( j1 b2 t1 l* W- b
* the actually available RAM size between addresses `base' and
1 C, j, ]- G" s. M* `base + maxsize'.9 k! m, B% _6 R$ h. G x
*/% t4 N; w4 U$ r* B
long get_ram_size(long *base, long maxsize); G9 d8 {) t( Z" E
{! i, `) R" \7 h7 S8 ]! K
volatile long *addr;2 h. x) O" z' C
long save[32];
5 W* F; T% h' F' B& P long cnt;& m8 i' L2 T- I9 V0 m3 ?
long val;
% j/ |& m1 m: D; n: G7 X long size;
2 j! J9 X; I- O7 \. g; @ int i = 0;% L5 T7 w( s# u @- n
9 i8 T$ s3 M! C6 i$ d) a) a S
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
! I& }! e, J, _7 N, l+ W, S addr = base + cnt; /* pointer arith! */
9 v- w8 X4 D4 m, S( G sync ();, s6 a8 K* }. Z0 ]) a% m0 a* f( q
save[i++] = *addr;
7 e0 e' J3 Y# w. E sync ();6 @1 ~9 R0 N6 Q6 A& v/ g
*addr = ~cnt;, ~, r+ u) w7 u3 C( M Q
}
8 v! x! F; e/ j- K1 c0 O1 s. f: r
4 q' ~/ k! s. U addr = base;% ~" |) `. u# Z3 h
sync ();$ l# E( q. L6 Y: D* P7 ~/ Q& C
save = *addr;6 i" k: s3 K1 Q7 s/ f% i9 D
sync ();
0 N% H% Y# Q6 `$ d *addr = 0;
9 o. \5 C* v8 S. |, r) Z) q
. z$ P; V0 X1 g% m6 F# Z5 Y sync ();! n' {: w. ^2 L$ X0 O7 w
if ((val = *addr) != 0) {
. a+ `- w* b! }1 r" r8 w# ]3 e x /* Restore the original data before leaving the function., U9 Z* P1 L5 o: v- `* C
*/0 i! `$ e; f) U
sync ();
$ P# {8 r. p) e' }9 h+ O; ?" j3 x *addr = save;
5 z- [* i7 R) C3 P" M3 F& b for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {0 P; q! P* @# q
addr = base + cnt;
% A9 }; U9 o2 O& N K sync ();
( c4 B5 D! _5 P w+ w8 g *addr = save[--i];
. ^" {$ w' H8 w; x }% Z: m$ S. [" i j) U' i/ [
return (0);0 t. i/ b% B# G: c8 u6 V
}5 ~; X/ n+ e( j) G
7 m! h$ x9 a& y( b. v0 V! n" Z) w0 Y for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {' k& T y, T9 N/ M
addr = base + cnt; /* pointer arith! */, P. g! \3 \5 x0 K" S% f5 W+ }8 {: J/ e
val = *addr;3 B. p" d/ z% I
*addr = save[--i];: Y! k: l g7 G! i
if (val != ~cnt) {
; g0 Q& \! R9 T v size = cnt * sizeof (long);
% N; d' o- d a \- }2 m( R /* Restore the original data before leaving the function.
: s8 ~6 ~( T" x# m0 S8 | */* c! o1 B V5 W6 O
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
3 Q! j- h$ s2 |: b4 K& A addr = base + cnt;
3 X$ D0 u$ g5 Q+ o$ U0 r- T- y# [ *addr = save[--i];2 X& F" U: I" {+ g& a2 \. m7 t/ B* @
}
% E& K" A6 ]: _- T return (size);9 u+ }' G9 | U$ y' y% T4 p
}& b( v6 p+ c; L" G9 R
}1 T$ p5 T0 F! c, I$ V3 b" |
5 H# g# R, U9 F' D
return (maxsize);( N6 t) D8 m! c$ l
}8 Z8 Z# B4 [. ]! R, Z5 E
int dram_init(void)8 K7 u. n. ]9 U4 U* E, J# M- {
{
O5 v/ A1 [3 D% } /* dram_init must store complete ramsize in gd->ram_size */) Z) C u: O' w/ X$ A
gd->ram_size = get_ram_size(5 D" |" l6 h+ t) S; X6 j
(void *)CONFIG_SYS_SDRAM_BASE,+ W; ?0 e8 `' E
CONFIG_MAX_RAM_BANK_SIZE);$ M4 d. Z% _5 x- D) R
return 0;! z( [1 |8 \" z7 B5 i- j3 L
}) M0 z: D) @) p- K1 l2 o
9 D7 I+ k$ c. P8 E( ?$ d& O5 I
1 u/ Z4 j; P9 M( W
/ k$ ? I* e) N
- @7 v$ [4 t; y9 }% k
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
+ K; I7 N. N& T/ O5 E4 B, y9 b8 m8 Z- @8 b+ G i0 F
- p; u) C# s. n# s" E( `: d a4 ?% N
4 m# j2 P" @' @1 M# Y: F
|
|