|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:1 Y W$ @- N! e K3 T
/*
3 Y! d4 j0 H) F1 V* Check memory range for valid RAM. A simple memory test determines
! N5 T; E, ~4 ?1 k9 T# H* the actually available RAM size between addresses `base' and
! j T6 S. g; u8 d i8 d* `base + maxsize'.
5 y6 g0 ]- {$ @' x( |8 R*/
+ q- `7 v6 d1 A( ~long get_ram_size(long *base, long maxsize)# O6 v) S# n' ]$ H" e- a
{
! r4 _2 K% H% F* [ volatile long *addr;. S) M/ ]) f7 o$ h; j
long save[32];8 Y: V, @$ s; V$ K+ X: v* P/ Q/ Y
long cnt;$ E9 Y8 @4 y" l0 d$ h9 o
long val;
1 g* ?; H# G+ k long size;
1 \2 q( \. X- `& D int i = 0;5 q/ O+ `) t$ l) a4 E8 y+ G$ G8 I* E
* K J& \; K. I9 R2 ^
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {8 ~) F6 d6 z% m% {4 V4 O
addr = base + cnt; /* pointer arith! */
* x( o3 r S+ G! p sync ();
8 Q6 j- \- |' B+ t0 s- M save[i++] = *addr;, u- Y/ ]3 s3 g" ]
sync ();* Y3 i) p7 Y* W1 f
*addr = ~cnt;
O/ V. Q! F/ n* y }
# X d- U2 w% Q$ p5 O$ C9 j7 t
' X" X; n, {/ ]: j* I2 z6 Z addr = base;
2 M% f; G$ g5 E# r! r sync ();) X x5 |7 u Z+ b
save = *addr;+ J# w* _. t3 y* W5 C: i; m
sync ();
- G! q0 m$ z2 L *addr = 0;3 C& y6 i' O: r
: Y0 O! g; I- J8 |6 x1 K6 V( Q
sync ();& V. g8 I8 N( T! D# a2 P6 U% a
if ((val = *addr) != 0) {
- r; u, }3 G; L /* Restore the original data before leaving the function.. r+ i6 k5 T" Y5 z; i
*/
3 G# {9 e: y6 K- h7 L, U sync ();
) L% c. @! X: Y) h: P3 w *addr = save;
, D+ [& n2 P1 G$ T. m8 l for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {! a4 H- K- Y; t/ f8 l
addr = base + cnt;/ y$ o Z6 p3 O9 g
sync ();
N; R1 f6 s8 I" ~, R$ | *addr = save[--i];4 O' t/ f' `* {3 U" n. y/ G
}
' a% A$ Q2 C) {0 ]' ^+ u4 d P# ~ return (0);
2 B* E' o7 H/ w: ^! m9 P }
+ P+ D1 V8 l6 v" }9 n; v$ y% U o+ `/ h6 t3 E, S* C a' l
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {; d# x8 _/ Z6 M R
addr = base + cnt; /* pointer arith! */! p% R# q4 y8 h2 l
val = *addr; T! R. A9 k2 U& V# C( ^- Y i2 J
*addr = save[--i];/ h& k$ A. N) D
if (val != ~cnt) {/ H0 H9 C. {2 N+ [1 G) r1 }
size = cnt * sizeof (long);2 x M. W+ z4 _4 C# M
/* Restore the original data before leaving the function. ~) |6 T1 t2 \/ O7 Y( O/ Q
*/3 X. e) W/ f0 E- Q* c
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {% P* a. C8 y4 o7 L
addr = base + cnt;+ g9 ?! d# {/ t+ {( j
*addr = save[--i];
* _. y% b$ A4 e }% ]! C+ k g0 G9 |0 D
return (size); l" W0 C* S D6 C# D7 }- C
}
6 O% q8 n. z2 c }
2 [6 [5 S T. h& w- { R p' A L8 |$ h
return (maxsize);
# _/ x; \/ F& _7 U( N! z}
3 Y" }4 x5 ~9 y7 u' i( _int dram_init(void)
1 I( q+ q6 ~/ }' i{% Y& ~0 d9 j, K. e7 Y* B
/* dram_init must store complete ramsize in gd->ram_size */
, F5 n. I- z, y) c9 b- V gd->ram_size = get_ram_size(1 m/ l2 S* L1 X
(void *)CONFIG_SYS_SDRAM_BASE,0 I& J9 o n' z8 k# Y
CONFIG_MAX_RAM_BANK_SIZE);
3 q3 u+ T) E6 _: U return 0;
~+ o1 L7 s) |; s/ M9 R Y: R}9 q' q; _6 @' _/ e
% B5 p- C$ f$ m1 n. f! Y* U3 X
) v" T% b1 o( Q
- e; f6 |8 j1 v/ ]
$ W4 m3 T6 c$ g4 x. y1 oFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!8 h! ~9 d3 Y. M9 J {5 i
) B, d% A% K1 Z6 v
# F: {, a- P/ T
P6 Q! ]# c9 q0 z |
|