|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
: Q" R6 ^: f! Z- a' c c1 y, T/*
" Y- g6 u! f" T3 D/ r+ M; G* Check memory range for valid RAM. A simple memory test determines
J- _: n0 u9 R) \# f+ N) `0 Z% c( L L* the actually available RAM size between addresses `base' and) e" `4 ?: g, v- Q
* `base + maxsize'.
8 U& z0 j8 \7 \# N" d*/: R" G! S2 p6 p# D
long get_ram_size(long *base, long maxsize)# b3 Z# O1 B' S( D' A' W
{/ y+ z) [; ^2 v# n. F. j2 A) M
volatile long *addr;5 d. w( `' o6 x: P' S. f8 L
long save[32];
0 ^/ Z0 Q3 p* Y7 j long cnt;+ s. Z& T( b7 d) k6 V8 E4 Q
long val;
/ b2 S/ M* f/ p3 Y long size;
' ^0 c) v X m0 l int i = 0;
( @! S, p$ x3 m$ g. u* F" W" G4 g4 t1 G
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {- [3 @( W/ s5 e8 B# I- o+ U
addr = base + cnt; /* pointer arith! */' \; N$ ^" v) S2 y+ Y# d% g) V2 f
sync ();! o6 t4 k: |" b. V/ m" i
save[i++] = *addr;
) g. R0 @8 Z& D4 o! K8 o) n1 h% N sync ();
- W' \& U2 U; R! [7 K *addr = ~cnt;
# N/ C* N7 j+ }- d }
" f4 a' v" V/ P" W' ~# I2 e
6 A( ]( R T0 x( y& A; N addr = base;9 n! w" T. K! h- K$ W1 }5 D6 {
sync ();4 \ ~8 x7 n; ^% x4 U- r% D
save = *addr;
% V! g/ v3 D( J- A; T: ?+ U sync ();
* Y, l6 z2 N9 l+ L& T7 s *addr = 0;
/ ?- V" x( t6 T1 l- v- e
% k) V+ J& Z, G7 r8 x' q+ L sync ();% e* C+ Z' V8 m4 ?; `
if ((val = *addr) != 0) {2 x, j3 r9 V/ P* h2 ?* b
/* Restore the original data before leaving the function." Y" _' Z; v3 n9 m
*/5 p; s" a# W. _, d
sync ();
1 _' u( Y9 v+ O' p7 N6 R *addr = save;, D" {; U* w/ j0 k
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
5 \) h6 @$ M- c& y9 w# ~7 S! y addr = base + cnt;
, U! z- A/ M7 ]0 q5 A: b1 n sync ();- g2 y5 o/ g- F: O: `4 M" ]
*addr = save[--i];
4 p3 l# p: n; o' H# ?. _9 i5 _ }$ v4 y4 l2 P x- k+ E: ?4 H
return (0);: \( h# z# G$ u1 l
}2 I, @) t2 k }- p% [8 {
1 o+ ?/ p- H9 L4 b3 s5 w! X) o* \ for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {! d7 A( S% c2 p' x! C+ @+ X- h1 I
addr = base + cnt; /* pointer arith! */2 ^. h4 s8 R$ k( e
val = *addr;
. m% j9 ?# b2 U7 U *addr = save[--i];
V7 e$ Y. k7 {, h7 m if (val != ~cnt) {
; _! B6 d: ^# N! I! E- g x* R size = cnt * sizeof (long);
4 @& H* T: o2 ^ /* Restore the original data before leaving the function./ I4 _' j# {0 a+ r
*/4 \! F: Y4 E) ^# n8 c+ S2 l9 |
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
! n S0 L+ ]$ z: v addr = base + cnt;3 E' J9 j" K7 Y* L6 j3 B2 x
*addr = save[--i];1 |# B* o1 U' G. t- T& V
}' e/ j _2 g: C
return (size);
$ ?7 `* Y) I C! ]" P; Z7 U }5 i) _ y6 x6 Z+ \: g0 A
}0 A5 G1 S' }- n4 A
: X$ L/ r4 E. K w3 R return (maxsize);
* f L6 b0 a8 d& Z, x}
& Z8 ?1 Q8 }: b) ^2 Z" jint dram_init(void)
& i- z& R, j& P- R2 X{1 t+ ?( n& }+ g7 @
/* dram_init must store complete ramsize in gd->ram_size */
2 E' E" M% B, R9 Q/ }+ C6 q gd->ram_size = get_ram_size(
" h5 ^0 |% c! |; e4 o (void *)CONFIG_SYS_SDRAM_BASE,
5 \9 n8 V; Z# E m" m1 _ CONFIG_MAX_RAM_BANK_SIZE);0 l$ j0 n' e8 ]$ P
return 0;
. B$ w! [% A5 q2 q2 ~}! H9 t+ |6 a' l$ E
" t9 o; P5 i, P ]# a
e0 m6 I6 a: z1 |5 X
9 ^- B+ o8 x* p) ]" ~+ ~
" Y% i* `9 s* |( S! EFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!" P. ^5 n |$ x) f+ z$ J5 z
9 \( a. O7 m. }2 ?6 d& f" f" V' M
& t6 {4 [# n4 d1 C8 U
) L" t4 L* [1 ?& i- y
|
|