|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
5 k0 E# n/ J* X/*
/ ~! E8 C9 d5 Z: M8 }* Check memory range for valid RAM. A simple memory test determines
& C1 J& F- h$ B3 L D7 z* the actually available RAM size between addresses `base' and
3 ^0 J3 M2 m" N7 x1 t' g* `base + maxsize'.
* m8 z- }8 ], S# j l8 Y7 ]*/
. V' Q% C0 t8 F5 x( ~long get_ram_size(long *base, long maxsize)+ ~7 k- p3 V5 R
{* Q" p; ^% V: P* e, @
volatile long *addr;
# y# N! H( \. N& _ long save[32]; c4 \# U1 T4 V. o# \9 l! k# ~
long cnt;
* b2 E) |3 N7 @8 W- t& [, I long val;; l/ c+ d5 ]; c
long size;
- ?& V" b7 |$ L1 Z% t' z" p int i = 0;" ? e8 g7 j* I) b% j6 l
- f$ }' I% r2 x( T- C5 Y
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {7 n. Q( w. p6 _# i6 t( d d
addr = base + cnt; /* pointer arith! */
+ _0 @% B8 p: K m sync ();
' E3 c0 u6 @' G4 s+ x: B) N save[i++] = *addr;
* c1 U% R) J2 x+ r sync ();: ? `5 y" c% z! z4 \0 ^
*addr = ~cnt;
7 ~" f" x; q8 p2 G# m3 d' `# g }
9 q& ~2 H4 a! v6 m+ L2 _+ i! I- U1 r& K
addr = base;
( b" G, r7 M ` sync ();& n! P( i' P! r+ L; ^
save = *addr;; Q4 k* Q' u+ w8 }+ Z
sync ();
, e5 U$ n( `# ~" z& o *addr = 0;# [ Z. B. f' S0 Y0 t- ]
; L% a% D, z. h& \# K
sync ();+ R( O! W4 K* x! {; Y) u& y
if ((val = *addr) != 0) {
; N" G1 F% |2 G /* Restore the original data before leaving the function.
, d5 y+ N M, M2 S */ T: q& R- @1 H3 s# ]' C* u1 D
sync ();/ [' n! Y. \% p k
*addr = save;. M% s8 m3 Y7 `( _. j
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
# D3 k' x1 l% K* { addr = base + cnt;
. h9 [8 F8 W1 i sync ();1 A$ ~( k. r+ j3 O
*addr = save[--i];" X z* Z, B+ f
}
: h2 G0 S- g3 R+ H% y return (0);
0 V" O) d9 k. {. m+ \ }
) n5 y& G- L" A9 h& V1 J
0 |* F0 u7 x8 j6 e! ~6 e: e for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {7 f5 r3 R; Q; b0 k$ s) M
addr = base + cnt; /* pointer arith! */
4 U. d( b1 U1 Q( _8 c* R" Y val = *addr;
3 q. S+ A( ?' W2 J1 Q$ r *addr = save[--i];
, S* G- k$ H. K8 M/ E/ S2 Q if (val != ~cnt) {
% J3 F- F- k& C# N- L8 \8 ]- T size = cnt * sizeof (long);4 V" D' ^4 N' v
/* Restore the original data before leaving the function.
c3 i1 I& P3 z! a$ j, m: h. R9 L */' G9 n" F3 ?1 I; c; d
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
7 ?# R) D$ |$ f! W, [, s T' y addr = base + cnt;4 v" p4 ~/ Z! a' x; b- V
*addr = save[--i];0 d2 e( H: V# U* v; y+ x
}' U& m: o# f' b& U, [
return (size);7 j2 r. Z) D. U9 k( S; ]
}
. l* E4 H& r; n7 Y! n1 z: v t( H }
/ y' o: n: i5 f: w/ \3 R, T5 a3 d' ]( o
return (maxsize);9 Q& _, d; Q1 Q& u S
}7 f0 @. |* h8 E8 G6 U5 i5 |0 ?. Z1 Q& r
int dram_init(void)
4 \+ b% G0 N N; v2 i' n{
# _: T- {6 F+ x7 Y! D- Z2 }- X _8 f /* dram_init must store complete ramsize in gd->ram_size */
- M; e7 x3 Z# V, e* L$ N gd->ram_size = get_ram_size(2 T) K9 n% S- ?+ F8 f1 C4 h
(void *)CONFIG_SYS_SDRAM_BASE,; W& D' Q7 y0 I3 I
CONFIG_MAX_RAM_BANK_SIZE);
$ ~3 ^- ?! [; N return 0;% U5 Q; y9 X' ?7 A
}
4 a( N) ^# a4 E# B% Y
' b4 ?0 g& F2 e( {
& n7 `' F' u, k% z; |
# t: {- |, Y* e8 N) a: _8 L4 D8 I2 J
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!$ t3 T1 v6 p: u9 L2 F5 I
- Q+ Z2 U* Z- ~+ V0 R% i9 [4 D' m7 y
Q( R3 |* f' T9 a. c3 q0 x% C |
|