|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:, k( D2 _0 q9 P8 n! J
/*; e1 j* z- K+ l* O0 k
* Check memory range for valid RAM. A simple memory test determines
& E w0 f, R& X; `* the actually available RAM size between addresses `base' and
9 d; Y' K' Z: }8 ~8 C/ _* `base + maxsize'.
0 h6 K3 X$ ?& i; G1 B0 c; ~5 K0 n*/6 @' a/ g& @" h# {: i
long get_ram_size(long *base, long maxsize)
% I8 a2 D F) f& R/ b{/ V0 \+ f- O4 i: v
volatile long *addr;" z! X" ?# f2 c$ }# _8 Q/ s5 [
long save[32]; R$ S5 a0 g4 O, v
long cnt;' q* x7 ?! u6 n' `4 P
long val; a3 f% M2 c5 Y9 E4 s* f' X# C
long size;3 j- e& ]3 n+ F, {/ Z, T, G
int i = 0;; Q; V/ f& M% \# E
1 f) D8 X! u. ]0 r) q1 ` for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {6 q" D, G2 D, l; p! n, l
addr = base + cnt; /* pointer arith! */
) }1 r: F d1 P: S# R+ b sync ();, z1 e8 X. M$ X, L. m& a
save[i++] = *addr;
X' e7 f2 w0 ]2 k4 B- ~7 y sync ();) r7 h) n: V5 d/ z! c+ b* @
*addr = ~cnt;
5 Q- S4 q/ c- b! K r4 T }
( S& c( s9 x1 ^2 K W
1 t5 b/ \9 Z5 a# a. ` addr = base;8 k; O' b! M* c7 e: m7 m+ X7 Q- d
sync ();
& Y$ P7 D1 D' ]8 j save = *addr;
. }9 W9 @ q% u9 L sync ();! p* Z, U) s* S- ?; K/ p
*addr = 0;$ P& x1 h {8 r
- H2 y1 b. |) a _ sync ();
H" J8 F: v# l6 Z/ |) M8 S if ((val = *addr) != 0) {7 z# N6 L7 i/ o8 D
/* Restore the original data before leaving the function.. `4 z' g N( j' d0 o
*/ n: J- `0 @) C
sync ();
" L9 J' E" G: h _. g; j, |( N1 Y *addr = save;
. D5 j: r+ [% J for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {5 \3 d4 E2 Y0 m* b8 w+ l' n
addr = base + cnt;
8 p8 l# R# D# @7 r! [0 z! n sync ();
" Y( w9 v$ Y+ j8 m8 { *addr = save[--i];
5 C j' J) }6 Y- A5 r$ t% Y }
! n, I1 J: [( o; _$ m return (0);3 G# v) g2 V5 b/ f& Y; C
}8 ?/ i1 E# Z$ f% l3 O: L0 n+ Y
' a& A1 O. ?( T, g
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+ S* J5 T4 }2 `6 G" c8 e- g9 l% K9 i addr = base + cnt; /* pointer arith! */' _4 \3 {& s: _& l9 D# y9 N. K/ {
val = *addr;6 k \0 g1 G8 @$ c* O8 n0 [
*addr = save[--i];
/ l6 z$ T! s+ B l if (val != ~cnt) {% t2 ~/ O Z2 V, U% b& x5 q( a
size = cnt * sizeof (long);* O" j$ [' Q6 J
/* Restore the original data before leaving the function.
0 k1 b' C5 Y" H$ k *// A( Y7 C4 n" H
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
0 a) N- w3 o* w$ V, X6 [ addr = base + cnt;4 q' s' a% l& D) H( m5 n
*addr = save[--i];
: ?) a s( _+ p0 c, A& W' V" r+ q* X# n3 [. l }4 s" i; g. b4 E" i
return (size);
3 B; O6 U: f$ g- E }
' j' l8 f4 P6 s: { }
% X2 A) z; F# |9 {2 R7 ?* X) ~5 P4 c. x: ~" }
return (maxsize);
& ~- S. @ m9 _3 _$ ~" i}7 J" |; S/ T+ c0 R) [
int dram_init(void)/ c+ O# Q( ]: A @ `3 Y( t
{
# E4 D/ C; }( @: @ /* dram_init must store complete ramsize in gd->ram_size */: G' e% ~/ j( T/ t
gd->ram_size = get_ram_size(
0 r! G# i e! p8 `/ { (void *)CONFIG_SYS_SDRAM_BASE,
! N( H) O. _$ Q1 B" [ CONFIG_MAX_RAM_BANK_SIZE);
7 C* q8 {: p1 q return 0;
; H2 Y! F' | G- Y j) F: Q}5 T/ N1 J# w# H5 U; ]
' m7 s+ {7 }! _4 ^8 f
& X- C9 X% R9 K! ~: j, c4 U
. \* _3 T3 ?& f# P
% A8 N4 K7 g* s) W8 W4 ~7 q% qFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!- U/ M4 G/ L% Q% G$ U2 i% P
; N4 A! A6 ^. g" f) r6 X
- [: M. W4 U, n/ |# M: V% y7 ~" g Q3 V; T2 g1 a) c6 {* b
|
|