|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:% M& Q$ Y! k3 a. h) o/ Y' T7 ~+ \
/* |- X8 H' F. |
* Check memory range for valid RAM. A simple memory test determines9 L: |. u# I$ f( @) ?6 |
* the actually available RAM size between addresses `base' and2 X1 U% b1 `1 b/ c7 M9 }
* `base + maxsize'.0 K0 j& Z5 q$ o
*/
; }- h- |3 O2 B3 h: R4 D, O) ?- ?+ c3 dlong get_ram_size(long *base, long maxsize)) s- ?+ y) ~8 J/ h8 L; F# `0 }
{
3 m( U/ s- l) T3 L volatile long *addr;
7 P2 i5 z6 h g5 P long save[32];
5 e$ p' e' G# S/ g0 x; a( o long cnt;( l# |0 Y, p4 ~, q; e A
long val;; I9 u1 n) j3 E0 A
long size;
' R* O: i6 p5 E int i = 0;
q7 v- }0 W* k l0 A) U% ]) P+ i# q# U. t8 t( o# ~$ z. u
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {! q! x) {7 l3 W( K7 V5 y+ a9 e
addr = base + cnt; /* pointer arith! */* B8 Q+ l( c4 y! H9 f: u
sync ();0 F5 N% h8 B# `0 y" b7 L) ]
save[i++] = *addr;
' t( E; t; Q+ d! J sync ();2 P$ t: i5 h/ D- n: {/ W E
*addr = ~cnt;
' |! X4 v$ {0 [ }3 R. D3 ?; B" V; d
( }/ ^, q X$ Q; Q( V
addr = base;
+ n; {* G, m0 E4 d7 w, v1 o" y sync ();
- P; v/ v' E8 }5 X. A save = *addr;
; Q9 u6 b1 @# h( {4 a, ^& B sync ();9 k8 G: C' O8 Q: U% ?
*addr = 0;. z' l7 ]7 G) {- _
% M2 |$ R, j2 H4 r! N
sync ();
5 x4 X& y: }( W if ((val = *addr) != 0) {5 Q" p m5 k. ?! v, w6 ]
/* Restore the original data before leaving the function.- p8 ^$ d. r3 `) C& b
*/8 ]: k9 V$ |" v
sync ();
. ~$ N& r/ k# B K* M( m *addr = save;* j1 @) i- b J: F$ x
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {2 g) ] o/ v5 X3 n+ k4 R
addr = base + cnt;' w; Z& G! a" k' N' H
sync ();3 R0 C) h$ o! Z
*addr = save[--i];
, y7 l( J1 I* J& k3 L! d/ [8 Y! E }6 D" A/ ?7 |! P9 G" ~8 ^3 X4 C
return (0);
0 o' m9 c; Q/ u4 X& y }0 a' Q) V) C: x% I
* {% |6 y# f7 d
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
8 L! H: f/ h; ]: y7 N$ X3 n addr = base + cnt; /* pointer arith! */; k7 d- E4 r7 E3 L! c- D
val = *addr;
) m- C) ?1 y9 z4 } *addr = save[--i];6 l; x& d/ U7 X
if (val != ~cnt) {
, k* E9 V1 s' y size = cnt * sizeof (long);
/ e& G b# g2 m# s$ s# G9 K2 Y /* Restore the original data before leaving the function.# B: r; E8 I' W
*/
& j2 \* x4 V6 t: N6 @8 Y' V) \ for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
7 g/ R& }: F0 ]& }" {, B' h addr = base + cnt;
, B& S, `8 t# J# ]4 {8 x *addr = save[--i];) m* l/ t0 Y5 @
}: q" U: T- x9 K- Z+ w
return (size);
7 k1 w. h' S* Q4 w }
+ I5 U7 F! q" c3 d$ ]9 t7 |7 s) h! G }
& w& E$ x) }8 S0 s8 X
' S( s ~9 w. w return (maxsize);9 e, x% U2 I- _3 c3 A* P
}+ A9 x# w7 s2 N. _
int dram_init(void)
! _9 W+ b k/ k/ n' w0 |5 f{
" V. O9 c9 E2 @, M2 h9 `1 G /* dram_init must store complete ramsize in gd->ram_size */( |7 n. e' u+ N% H9 R' \" ^
gd->ram_size = get_ram_size(
2 C) G7 l# x1 o+ P+ b4 m, j ~# q (void *)CONFIG_SYS_SDRAM_BASE,
$ w7 N6 K: e$ S2 ^ CONFIG_MAX_RAM_BANK_SIZE);, i* r8 Y' d( }
return 0;% ]) n, L, s3 X! e0 L- o: L, i
}4 N4 r. g+ S( a. T. z
' S" j) C# Z- ^" ?8 v* j6 \$ L5 i/ y" ]8 L
1 x( p; b D! Q o
( q' v: p# Y1 PFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!. F" p4 K: F( @# a m
! P1 V4 J9 N1 t
0 ]5 e, n! i" C2 D; Q" }$ M: J% R7 @4 k5 p) D2 S* e6 L" u
|
|