|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
6 b' d# a3 U7 i& A+ I/*2 H- [6 x# f3 ?2 Z0 }% k0 w
* Check memory range for valid RAM. A simple memory test determines5 W1 g5 b; D5 `- v
* the actually available RAM size between addresses `base' and
5 d! R( N! `& _ ~3 \* `base + maxsize'.
% P5 W% p4 m( [5 D6 r0 R, a# a*/( v2 [3 ?$ a4 ]) ~8 Y2 G1 i' @
long get_ram_size(long *base, long maxsize)
' l# K0 b0 G# ~) P0 y! `; Q{
# z Y+ l# V3 ^% f; ]1 Y5 g volatile long *addr;
6 s1 O" A9 ~0 N8 v: w1 `1 f) U: J long save[32];
$ p4 o& m+ h4 O% B, N5 v+ P5 ? long cnt;0 Z7 O5 A% |2 U* X$ L3 L
long val;0 A9 L/ \- p+ S9 V F
long size;
6 Y3 p8 d2 r( a; z int i = 0;
7 S; E! J8 ], s }1 h; e/ x" N3 y9 ]" ]$ g
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {! L9 r9 q7 R$ I7 q
addr = base + cnt; /* pointer arith! */' R, P! \6 J) T
sync ();
2 L/ n( w8 G0 x& _( G( t save[i++] = *addr;
, c' l) a4 U2 P; A Y) D sync (); L ]5 t# Y5 X4 q4 j/ I6 G, h
*addr = ~cnt;! D- p; P7 R, x, ]& _; N, H
}
, H- I/ O8 h4 j' l$ R$ I3 w/ n' z! p# B5 R, Y5 O
addr = base;
6 M/ _- b7 M: c, y7 X/ \, B sync ();
9 h) M8 D j$ K& d! h# ^% u; { save = *addr;5 a8 ~8 S3 I i- H6 T1 N
sync ();3 q/ p; X% D4 m: [2 e z
*addr = 0;
: S4 T6 I J7 g. b0 B9 c" R) S7 G, P0 ]" U- W
sync ();
. l# C+ p7 z H5 o2 P6 y if ((val = *addr) != 0) {
3 c4 ]% P* m5 H- p3 O. |0 A /* Restore the original data before leaving the function.7 d$ ?! Y' X; w3 w
*/
' h7 z2 F+ w9 ]7 M' w W7 y sync ();
. b W y6 \& H5 u% t *addr = save;- ~# v8 b' y; t5 e1 W" Y4 Q
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {, e- I, C6 Y; j; D7 j
addr = base + cnt;' W; S% ~! A, s3 M/ `' U' U
sync ();
. U4 f( A/ H6 ` *addr = save[--i];
0 p; G: k# s( \% F7 P9 N }3 Z! O5 u3 t3 Z/ N- m" X( ]* a
return (0);7 L8 J. x0 h- [* p
}
6 Z, c7 w4 ^ d/ q* k% p2 U4 n
, J$ a9 [+ ^0 ?# S9 i3 ? u3 ? for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) { e& [5 V2 H4 K9 ?' F2 Q
addr = base + cnt; /* pointer arith! */
; X" }( I; x* g: ^1 @ val = *addr;/ V# ?: |' O; B! Z( ~/ V0 b" U
*addr = save[--i];
; {( R3 P3 B8 z" g if (val != ~cnt) {
. W( X8 h8 D8 D+ B6 l2 D- G y# O' Z- r size = cnt * sizeof (long);' [# X1 r3 ?# h8 S5 {9 w
/* Restore the original data before leaving the function.
* ~$ f( C, N& k8 t# Y* S */
* j! U7 L3 }& n0 [! g for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
- l' `: O$ b- m/ S4 z K addr = base + cnt;
$ y& r4 ^ _4 X6 |) N *addr = save[--i];
$ P2 G# @( ~0 O8 |; i; y }. X# j8 ?3 b; y( B% z
return (size);9 X; q9 y- ^4 ]$ A5 H: _9 n/ F
}
. l! P* r! |. J$ ?- R( ~ }
" y% o" p% C+ |" q& `! Z4 p* t' i+ E
' |$ ^( {, E$ |1 y+ C) T2 ` return (maxsize);
* Z M" M, d& n# L}
! ~( F N+ n$ p* iint dram_init(void)' p Z u& v" Q5 h9 K
{
" ]( y' q' q; _3 r0 x4 o$ a1 p /* dram_init must store complete ramsize in gd->ram_size */
! `" X& `2 U7 j3 K( I gd->ram_size = get_ram_size(, ^6 F, x9 j8 w) q3 h& u0 \$ f
(void *)CONFIG_SYS_SDRAM_BASE,
) O: ?- I/ e& Q' _5 h t, v6 h CONFIG_MAX_RAM_BANK_SIZE);5 V+ J) F4 A- N' V1 w% D5 @( G# e
return 0;
$ |; L0 X, N" K/ C" m% r}
& q- y$ h5 d, \& M* X2 f# P% I( F% A
3 ^& J3 o) d0 x) t) ?: v
/ ? T5 H1 A0 x- J7 _; P# O' J. C8 Y4 Y! [1 T* T1 X. Q, c5 E6 ^
7 F: x: G& e+ PFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
; S C3 e/ \, v5 R' i6 y( R; P% e2 W2 V9 d0 Q
9 D o+ [ o# m: I- e
6 v) i. H) r% j |
|