|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
q. X3 W H1 i$ ?4 ]* S/*
3 q6 `- P* B7 _5 Z6 ?5 C; @* Check memory range for valid RAM. A simple memory test determines
2 R& y7 `2 {8 n( l, R* the actually available RAM size between addresses `base' and1 K( S# k/ t y3 O8 i$ x. F
* `base + maxsize'.
3 U+ Q$ a7 o( z. V+ v*/
; m% E6 Q! s8 z! glong get_ram_size(long *base, long maxsize)( C' n; r/ h* f5 d
{, F7 U% ~% d7 v
volatile long *addr;; I1 P0 `4 n- c! D1 G
long save[32];
1 u4 a! D3 N# m+ ~$ C B) Q- Z4 f long cnt;+ s& `! s3 ]2 z7 ~: A( }
long val;& q' p7 ?) A% [* H* v9 s( z
long size;2 t; D4 O/ A t4 i: X, Q
int i = 0;
/ V0 h' }6 @ f! M$ v+ X+ f2 f* X, h
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {( {: `1 T6 ]3 Z* X
addr = base + cnt; /* pointer arith! */! @0 O+ x# G' ~" J7 ?. J
sync ();- r1 C0 u3 n `
save[i++] = *addr;
2 b. n+ ?: ?% G sync ();' j, }* q6 E/ K! t ~; h) M
*addr = ~cnt;
, s! ~/ s6 s" K4 D- U1 h }% H+ }* T5 m& I. k0 K5 X. ~( o5 U
+ p7 k' J0 a9 T addr = base;
. y& s; n5 d* l" |1 V3 ` sync ();
* p) ~1 H$ ]2 `0 E- l* s3 ], G- \ save = *addr;5 F- \/ {9 e# }& J
sync ();
5 \; j$ \. r$ s$ Y6 }' Q5 e. J *addr = 0;
0 i; N6 _2 C( ]1 }" C9 m7 y; A0 w I- ]
sync ();5 A: b# ~: h$ |
if ((val = *addr) != 0) {; M6 n& n1 p6 D
/* Restore the original data before leaving the function.! k* g. F* l$ m* l$ j4 Q% a
*/; o. j# T/ r- [% u; G0 I
sync ();
8 @! N0 q- g2 |4 i M! m2 C *addr = save;+ O5 [5 U6 g3 o" ]
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {0 N0 x7 Z7 m+ i
addr = base + cnt;
$ j8 D$ d) ?6 o sync ();
" D% I8 b6 i0 z8 s6 N7 O) W8 S *addr = save[--i];! z: |( Y8 S5 s: Q! H9 X' A
}
7 I! m0 W* o' L7 | return (0);$ N3 k) P8 y$ O6 s, j5 \0 R3 r
}7 d3 k3 G7 a9 T/ `' ]; |
5 I( [$ ^# y( @ ?8 S- K- O
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {. A# H; s3 {% c' d* h% W8 Z- H t
addr = base + cnt; /* pointer arith! */
) K0 Z$ v+ D! X' _ val = *addr;/ l j. Y2 b+ T5 Z3 h
*addr = save[--i];; S# d8 r* R0 F' f7 a
if (val != ~cnt) {
$ d% L5 Q0 _. C0 r" e6 ~+ o size = cnt * sizeof (long);' x. |- Z- t, V- Z' ^( J
/* Restore the original data before leaving the function.
1 {5 G( W* ]+ G2 B */
% g& C3 [% `3 G' f/ Q6 P4 P1 p% P for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
% O" i" [1 }: |/ h8 \) s2 m1 z% g addr = base + cnt;
" R! k' d6 P+ p( [/ } *addr = save[--i];1 c. Z8 P) C! W5 `4 T
}
! K/ X) \2 j; B3 K return (size);% e j& `/ t/ l$ o4 s
}
# I2 H" ?& h! V _ }
% r- E* T: J: R% m4 F7 ~4 V- c/ ?, q" h: {/ C4 s+ z
return (maxsize);
1 Y1 P% }# M; u: Z; u}
% H( T" C4 _6 b/ q6 Zint dram_init(void)
, M) w6 O! n0 Q, `{: C4 g1 B/ t# q# w- k
/* dram_init must store complete ramsize in gd->ram_size */4 M( b: V+ S8 B- a, u# V
gd->ram_size = get_ram_size(. L6 Q$ [; j) b" S' t) H4 f
(void *)CONFIG_SYS_SDRAM_BASE,
2 J% W b2 N6 p* w; Z CONFIG_MAX_RAM_BANK_SIZE);
* X) U y8 _, B- u; z g2 N return 0;
$ c4 M, ~6 x6 x V3 D6 x. v# y}
& ]2 c& X$ `+ D7 J ^6 `
4 G% n* y7 \% i) N
+ L, X& T9 x, Z3 T' R6 D* @& l9 L( r' `+ Y7 C$ [
9 o7 t# D- D% e% x! l [
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!$ k4 y9 `9 U- l1 D) ~. e
% s# U# `; m. p+ d m- R5 w
6 }1 n; v7 x9 w) e6 \" W
" V' I1 _" q( ]# g
|
|