|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:. q; F$ w7 M3 t, ~- N9 @. y. |
/*
) M, L" @/ H3 g- J* Check memory range for valid RAM. A simple memory test determines
# w. B8 z2 q9 P$ G* the actually available RAM size between addresses `base' and
. G5 _8 M% O8 M) p9 m2 n# Z* `base + maxsize'.
l8 J; M% ~3 b" r, X! h! c*/+ W1 [5 I4 L7 |$ B$ i- x
long get_ram_size(long *base, long maxsize)+ R4 o. X8 }1 v
{7 |& i0 ^; j3 ?
volatile long *addr;
, ^+ u: Q+ m" q) t9 T# y long save[32];
8 T: v% I( A7 h; C long cnt;
# x. J: o- P( T2 F W5 _2 f. a long val;
1 D; q/ [/ Q& c$ q long size;
! C% F" w1 m& c$ B& N6 K int i = 0;
9 G- l: f+ H5 n& _$ x6 f
0 Y* n; r6 E) k& }% m8 S$ T7 b$ s for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {- z( x" e+ f6 }9 n+ d
addr = base + cnt; /* pointer arith! */
8 {* _* M8 v1 c sync ();
; a9 W* p" K6 F7 I save[i++] = *addr;
+ |& w+ z# ]8 J' t$ K sync ();+ y' J* ^* K7 Z4 I
*addr = ~cnt;' A# C8 W- m5 r( _: T5 V
} \5 v, }- z: y7 H; w" Y: \
. `4 Y, S! z5 i( H
addr = base;# g3 H: r- X O) L& K8 d
sync ();/ j: V# S( d) a5 x
save = *addr;
! M$ G: ]. ?6 e" [6 M- u# Q: M sync ();
" k- y" d. Q# ^ *addr = 0;
" Z8 `/ P$ z' A: O
0 p: P) Q( }5 n& L- q, e sync ();' R {4 r) w* {% I5 V
if ((val = *addr) != 0) { }6 ]$ G T& F; f5 C
/* Restore the original data before leaving the function.9 S3 u+ d' x" I, P j
*/
, X8 V6 T% L7 H4 t3 c/ k7 ?- _ sync ();
% X- }' S" `) f' t$ }" k) t *addr = save;
& ^* b& i7 d. _ for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
+ k ]7 Y' W( R# { m* i addr = base + cnt;
! ?" H& a/ Y R sync ();0 |" Z1 x8 C0 R2 e3 E
*addr = save[--i];
" g, l) b' f% s% R# L }4 H7 V9 I2 X9 f- D% \
return (0);. {' p7 K9 v2 ~6 e/ L( q
}3 H- K0 ^! @5 M7 p% ~9 x7 O9 r4 `' J
% J/ w7 R* X7 G# B7 `5 U for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
U8 b( e: w* V. L' ~. v addr = base + cnt; /* pointer arith! */
2 @' O9 o' E3 C- { [5 _; ^ val = *addr;
2 ]( l1 a5 H: H* e# ~ *addr = save[--i];" ^' s3 d: E0 T" d
if (val != ~cnt) {
) q1 e( l+ ^! J( Y; d) w size = cnt * sizeof (long);/ H2 n0 a, y* r; U
/* Restore the original data before leaving the function.
# \( j, J/ m: d8 i */
/ L9 A( L8 s0 A& l5 [ for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
/ p$ [6 G2 o8 h4 z. Z2 e; z addr = base + cnt;) g0 S+ ?2 h6 R3 {
*addr = save[--i];
: ]% e# j' O6 A6 T }& I0 F! m5 T/ k' p; e
return (size);
0 n. P( v8 l7 k- }8 c! G }
, F; I* K4 L3 e# m }
# b3 C$ `4 J- B6 p8 u0 I* s
" d+ ~0 ^' E% t& \6 l return (maxsize);; `$ L) K1 b1 a$ T! A
} N4 b" O7 S: A( F1 L6 ~- l4 O3 a# a6 L
int dram_init(void)
! f2 @5 l8 E) M: Q0 _" G0 \0 K0 \$ W3 n{
5 q8 _! b. e, ~4 W) ]; i /* dram_init must store complete ramsize in gd->ram_size */
: Z6 D/ Y R4 R$ U% e/ C5 V. r+ P gd->ram_size = get_ram_size(
; S0 k$ P: s% \4 O- l9 _ (void *)CONFIG_SYS_SDRAM_BASE,9 P5 \1 P, k& a7 V' q; o/ u
CONFIG_MAX_RAM_BANK_SIZE);
7 o* o8 e( p/ ^( z6 D: a3 Z' M8 h return 0;
: f2 q8 e+ u: d' d}
. q; Q0 {( V4 G: \0 X& @
+ w" a6 b& ?$ v7 @
% o3 T# T' B- b. S
1 \/ @7 t( t3 u4 O& q* t) I* m! j0 Z5 b# p
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!& r9 |6 W. l& x) G+ `
+ W- O, Q' ]' m9 ~. ?0 v8 L& z& R4 Q& h# M# A) B y! m& D# i
Y% h) X3 z) D
|
|