|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:: Z+ \* B5 l" Z* D
/*" ^* M- S4 D; b# K$ r2 c1 j
* Check memory range for valid RAM. A simple memory test determines7 `% R2 l) c/ w
* the actually available RAM size between addresses `base' and
/ a( Q" }- v" Y8 z* `base + maxsize'.
* C3 ^7 _2 ~. M, C+ s) A: \3 C*/3 q. ?# l2 `7 t3 t3 e% [
long get_ram_size(long *base, long maxsize)
; X- b" A, o3 ^, J& @{, E4 D$ ?5 E, h& t' Q
volatile long *addr;
0 G2 O/ y! @0 t. G4 D* H long save[32];! S) g. \: `; ~. h8 {
long cnt;0 v7 R: \* q" d' J" U9 e8 e( P2 o
long val;! z6 Z; c3 A# a' ]) W
long size;* Z0 q5 k+ T [6 h J! V3 d a
int i = 0;
3 M) m# X# @, Y# U, x, e! g7 u1 \. e! l3 g. E
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {" u$ Q6 a3 g1 h2 l& S5 E
addr = base + cnt; /* pointer arith! */
) }& f N7 q8 O6 W) ` sync ();
+ u; S3 A& y X5 W" C+ Q ?. f& ? save[i++] = *addr;& }, @$ M2 Y; o4 @
sync ();" V. v5 m: _& |9 M& R4 W
*addr = ~cnt;
; ]" b$ X/ [ z# F0 ` }
* Q. ?6 L, f; K1 e5 _$ z8 M! Z' D8 H
addr = base;
9 o+ Z' t: a8 `! F& N, e sync ();
6 r6 Z( O& x% y% [: ~ save = *addr;
8 \+ R. R7 n a sync ();
6 H I4 i' R1 r, k5 T# I *addr = 0;" @! Z/ H2 `9 h
9 Q1 b, I( z( t sync ();& R+ f/ h, I8 @5 y6 C( h
if ((val = *addr) != 0) {
, E) Q$ b* r5 J6 c$ H* d0 P% Z /* Restore the original data before leaving the function.
1 R1 ], Q9 y' f8 x5 K */2 P4 N0 ^* n6 N# b3 v
sync ();
! O8 l9 a) G6 X" W: I *addr = save;
+ I- M, g; I/ s! y! h for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
5 T$ |0 j2 V; \4 O5 h: G# M; e addr = base + cnt;% T3 P% S0 ?. V4 @) Y8 W! j, [/ h
sync ();" c0 Q! Q% h, g2 H- j1 H3 W
*addr = save[--i];
! ~ q6 q1 ~/ g x1 x% c: L }
7 |7 r- b( I2 _% Z4 a: k return (0);4 m s" m) [$ m2 a
}
# t# E9 D0 b; Q* a1 x# I! Q2 R+ G9 i$ |, o& t
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
1 U, t+ {9 d) E0 v addr = base + cnt; /* pointer arith! */) C1 K1 f- u6 K5 y7 @$ v# Y. k/ r
val = *addr;. J+ q+ S" @' n# g+ H* o2 g; }
*addr = save[--i];4 n: L; Y+ M) t% L
if (val != ~cnt) {# f' ]" U& I: {3 F: |: H# x
size = cnt * sizeof (long);1 _" ?# g3 `' @: i% X
/* Restore the original data before leaving the function.7 z2 B4 N2 I1 J" t3 {
*/3 X) J! [4 \, ]$ V" d; ~
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {. N: a% x' j Y" y7 ~/ N
addr = base + cnt;2 L3 r9 h- s( a+ ?6 j" _, `
*addr = save[--i];
+ t# \% g3 z- ^ }& S& m1 [5 I2 J* E7 E, j
return (size);
# A6 e( O" ]% n' r }
$ R7 R3 a% P3 _ }
. s' _, X( Y) D: l, x) a: g! @) e$ ^- q7 t
return (maxsize);
* o9 d" Y& _0 N, _}# f% C$ E) ~+ F/ T$ E
int dram_init(void)
A. _% z6 M6 x$ t% L{+ _. [3 i0 Q" A0 c% N7 i
/* dram_init must store complete ramsize in gd->ram_size */3 d8 F+ b2 z, X1 U* l
gd->ram_size = get_ram_size(/ K( n0 W4 F% V% `$ U$ F3 D
(void *)CONFIG_SYS_SDRAM_BASE,% \& \, k: L2 {" P
CONFIG_MAX_RAM_BANK_SIZE);
0 z) c6 I- o1 l return 0;8 ?% D# ^& Z, n! X8 Q8 l, r' X
} n& z% ~0 ]" l4 b
+ i6 u& d) Z, M8 `# A
1 l3 C, H: u5 b. N! ?5 o+ M
, I! ?2 T/ D& M# a( t8 g w# i
5 d1 f7 _4 s% S8 bFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!3 ^& G; v$ n: b' t3 B* |
* i% u. n/ S& L1 S' G
+ C& [, F& P$ s) u, [( c7 Z" U$ f
9 z0 C- g% P; u' f0 V, j; G: C |
|