|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
9 _+ G8 ^3 I" l7 C( U2 O/*' h: B/ ]6 G# H" C
* Check memory range for valid RAM. A simple memory test determines+ {. O8 H- J! S p( J' O1 J
* the actually available RAM size between addresses `base' and) Z$ l* Q% D: w" n! ^
* `base + maxsize'.5 K6 b! k# k9 h. G4 }
*/
9 b8 |/ g$ y! i1 M% H; ?) flong get_ram_size(long *base, long maxsize)
7 |4 e* P' {" O$ M{
1 h6 S, M S4 l) |0 g volatile long *addr;/ O. M) `/ C, n5 _3 t
long save[32];) X$ C, t% n' S& E
long cnt;
4 h5 I e* B! r) C2 w long val;
9 L' [ q6 b& n long size;# |9 x8 K2 g: C3 S) U
int i = 0;1 ? \( t3 a2 X$ ]* n$ Q
* p. X* ]' v5 U8 @9 T+ a6 c% e for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {; c9 O& T& w% x% N# F
addr = base + cnt; /* pointer arith! */
* Z+ c" s2 f, |2 C sync ();
3 u) u$ ~2 w% D& q3 O2 q+ O( q save[i++] = *addr;
3 A' X/ M! o' n/ C, } sync ();/ w) g( m- {. @4 K
*addr = ~cnt;
. {; @5 t% D, U5 U }- o& d$ \5 t$ _1 e
1 L# A' a# ^6 n
addr = base;
7 z8 H+ C9 d2 `$ G$ L& o, R; ] sync ();
/ A3 a8 z2 C4 E7 Y ^% i save = *addr; U/ v, `! P2 h4 [1 g/ C
sync ();
! H, ?+ D( Z' ?3 B3 R1 {: { *addr = 0;
3 B b8 e6 X% ?: E* h; h
. m) l; G1 [) X& t4 H sync ();# T* R u4 L# u ?+ m' W
if ((val = *addr) != 0) {
$ M- S* k: l( N! ^ /* Restore the original data before leaving the function.( X( s: A; B# `3 X
*/0 `6 G- e$ c! ]$ B4 Z
sync ();
, a# j# B& W1 A7 v% x *addr = save;% C9 a" I. T. {: x8 X9 ?
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
0 M) J( ?( |0 b; v: r! g- f* | addr = base + cnt;
1 J9 ?3 Y$ }# B sync ();8 U9 ]; C. N0 C( t6 Z
*addr = save[--i];: n2 a& b8 v, { _) F( {" [* A
}
/ I- e6 y. x( G" _% J8 @ return (0);; T8 t1 S: w' V$ i+ }
}
" u0 l4 j O) e ~* E' C* m: Q7 r( J
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
% |. n3 {' F* M9 ~5 ^ addr = base + cnt; /* pointer arith! */( v( K6 n5 X" R1 `
val = *addr;
5 @' W; F4 d4 {* ^+ V2 [ *addr = save[--i];% g! C6 n* Y. u S# ]* l- n
if (val != ~cnt) {
, r5 w1 Q# p- Y0 b size = cnt * sizeof (long);
( [! X! |0 G4 N, k /* Restore the original data before leaving the function.
' \# |) B: U" q */2 `1 G, n) H3 m- c- r3 G ^' S
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
5 V$ K" U. V6 F. W: e; z. l7 V' s addr = base + cnt;
9 h# K, V% ^: `& [9 H+ d: p *addr = save[--i];! f9 ?1 }: M* c6 s8 C+ _4 n9 Y5 ]
}0 p$ Y w( U! E9 M
return (size);0 x( d& A! k; v( c/ S& N- c6 b9 q
}
7 w5 m0 {, c, z8 o7 Y0 | }
5 l1 B7 V4 Y9 R8 e( H7 g1 R* i$ g
1 t) q( A4 P0 f- ?5 g, e1 c return (maxsize);
, B2 h: X, z; d}4 S6 l; c3 Q! S. [2 H
int dram_init(void), l6 l3 V6 R' m3 |7 {. S Z$ `1 O
{
$ j& `/ L' _9 m1 k$ O /* dram_init must store complete ramsize in gd->ram_size */
% q7 Y2 C/ b; n3 n8 ~ gd->ram_size = get_ram_size(
' ^) @9 j5 f; x (void *)CONFIG_SYS_SDRAM_BASE,
8 ^8 M. n0 C7 Q: S CONFIG_MAX_RAM_BANK_SIZE);. K; I* J8 G* |5 n4 i# V' x
return 0;1 v- R; j( j- W2 M) I& k0 h6 ?
}; i! j) }! c% g7 r0 k
. K! I% l1 m, v m$ [& C5 q
# O& u! p2 z) R/ Q( H: g3 y1 U3 P
2 ^- A; U' [3 C9 s7 |0 x' G
/ P' Y8 |$ ]3 d5 `$ N) G, FFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
% @$ {7 k( w2 M1 C6 S5 Z* w! Z
6 ^% V6 W" d1 O5 x* o; c: J F' ^$ d: `: J+ z( A
3 w' Y8 v6 m4 e2 d1 M! U
|
|