|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
3 K; `& A7 s9 Q$ ?8 m _4 e+ Z5 e/*
p- d: |+ | n( `- A# \ m* Check memory range for valid RAM. A simple memory test determines! \3 I5 e1 }# \/ V$ ~: K6 h- u5 x
* the actually available RAM size between addresses `base' and9 M1 l5 w+ f4 p, Q( \
* `base + maxsize'.
' K t! O' V, r9 y*/
3 M% ?+ c, f- m. wlong get_ram_size(long *base, long maxsize)
+ M: @" b& j+ y- k; q{
) |7 Y$ {" ~) ~9 D( ~8 B! S! ~ volatile long *addr;4 C* c- k9 ?: R! b# e+ A8 k( @9 B4 n
long save[32];
; A! M+ M7 | L$ q long cnt;
! q" I5 V G2 H7 X ~+ p1 j A long val;( C# T9 |: S6 F5 c# e
long size;
: [, {3 Q9 C8 C4 W1 | int i = 0;4 t L+ u$ t f% j
; x S. g9 {7 S: q0 l
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
0 h9 L1 C5 T$ I$ V. f# J% c addr = base + cnt; /* pointer arith! */+ }6 g/ i+ d& V' ] U# O/ W
sync ();
3 s' N0 p( U# k! x5 ^ save[i++] = *addr;
+ m6 Y4 T( Q+ }; a) S sync ();' M0 H; _& C" M6 w- o" }$ {
*addr = ~cnt;' e9 U4 }. A3 \4 g
}
) g2 N1 i7 u7 H( m) x7 {: ]4 A& S9 K! | e0 z2 }/ R
addr = base;" f) \" h ^; C% o4 e2 D
sync ();
2 F+ ^2 Q% I3 o save = *addr;+ T$ B3 x5 J, K4 r3 B
sync ();) x3 P% n" E; {2 @
*addr = 0;! p0 H/ f. h4 w/ l5 c
; f* O) C4 I! s5 P( h. l7 m sync ();; x, F. ^( X" v& l( z& B+ _
if ((val = *addr) != 0) {
5 }4 t' I- Z$ z" T$ j3 K /* Restore the original data before leaving the function.0 A& E1 a$ g: r1 i6 ]
*/$ ]% C5 R/ G, I5 u2 F
sync ();+ ?- P: O- e. w5 z
*addr = save;
2 r* X! [$ B. ]$ z, ?* ] for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) { x8 c4 e h- j {/ Z" Q6 W5 Y
addr = base + cnt;
# u# q1 x! r# q sync ();& n; U7 ]4 G7 C) H' D4 P
*addr = save[--i];7 @% ?" m) `; H9 h4 Q
}
' L( i9 y/ b+ V/ y m" p return (0);
- A! f( P4 P( D" f# ? } E# L1 z/ c! L/ t% @2 N# q
& I. i& `% B2 D) j
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {' E7 n% f% }8 s3 u4 x
addr = base + cnt; /* pointer arith! */
" h L2 R+ D! _3 G5 d val = *addr;
# T5 n. B' d4 Q2 f *addr = save[--i];
0 x8 [7 q0 p- U2 n" Q" M, h if (val != ~cnt) {- T$ q7 Q+ t* Z6 |1 d! V5 q- U
size = cnt * sizeof (long);
" a/ C1 X9 p& ^5 m3 _* u /* Restore the original data before leaving the function.
2 D p$ C+ G4 h% a( k6 K4 V" R */
* O6 @! M4 o& a. E6 R3 @$ K for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
5 w/ |+ T1 {, t5 ?/ T$ ^* L addr = base + cnt;
, r1 x$ A5 {6 ~2 E' ?) { *addr = save[--i];
) w1 _7 \, w2 q }; v5 Z. |6 m2 E, b9 o; y0 G1 o
return (size);/ q' [) C. `" s+ A, I! t' h
}- b/ k4 G% j4 Q0 W% q
}
$ e3 w4 h+ ?5 K8 }6 F! X5 i) @! ^% z
return (maxsize);. n4 C, k+ V* M$ W
}
- F8 s7 X( c7 d% `' O6 [* k$ \int dram_init(void)
5 H7 s. t5 R. P0 G/ J{1 F/ @" Y# c5 ?) [5 `5 w! T. R9 p
/* dram_init must store complete ramsize in gd->ram_size */3 b5 l% y, ?* S+ I r
gd->ram_size = get_ram_size(
' ~8 w5 h6 L5 _9 F- n6 R (void *)CONFIG_SYS_SDRAM_BASE,
) O8 i: p4 e2 m" J. @ CONFIG_MAX_RAM_BANK_SIZE);
1 s/ U5 X$ W3 ], l1 v return 0; r, F- _) e2 _% H- s
}
% p7 a' d3 K0 ~1 {. ]- J9 V
8 v7 c& C) q2 M) u6 ^8 N. X7 v6 ~5 R+ I- T
7 I& R4 g/ `) B- n2 N. |
. F+ u2 M0 G& F" z/ l+ pFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
# S; j% x3 n5 ^! `" ]! `7 T# C: J
6 D9 Y# ^( D1 L! z: c0 q
7 d8 c5 t4 `# S) m1 _3 }
|
|