|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
- D4 ~3 [6 ^' g0 p9 S4 ]6 u/*
$ d$ w6 Q: A3 i$ _4 `' z& K* Check memory range for valid RAM. A simple memory test determines
7 J. D/ Z; U) E7 ~% I- f- C* the actually available RAM size between addresses `base' and. w/ S1 t% N4 C" s
* `base + maxsize'.
. f% K* ?8 C4 }$ e8 ^8 C8 A*/
- v) P% b/ R0 N' n2 ~long get_ram_size(long *base, long maxsize)
, ]. Q# g0 F- W8 C6 u{
# ~8 U+ T7 n8 F2 P8 R) r7 @ volatile long *addr;
/ S; T& X5 W- A long save[32];* _0 G$ d, d1 l4 `: y6 s
long cnt;
( _( t. m# K0 x) x! ~ long val;/ \9 a: A7 n6 Q6 a2 Z
long size;/ v2 M( }* p% O
int i = 0;
; X' [/ ]% E/ [7 K$ U# q# q D H% M7 Q3 ~1 W$ y4 y3 T
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {2 O( T0 ]' x" ?. C$ ]
addr = base + cnt; /* pointer arith! */4 U) g- `3 _8 G8 S4 s- b" v0 L) ?
sync ();
" |2 ?1 Q6 M2 G' |( Y save[i++] = *addr;: d) z9 Y+ Y& k( \
sync ();/ m8 s; G! N- \* _; l3 P4 O" n( c
*addr = ~cnt;9 c" h5 i; n! D9 M
}
: ?/ I6 b; {# z, t2 O
! R$ F a4 H& d3 k+ `+ G0 z addr = base;5 W' \+ r3 w+ o6 d" {+ f
sync ();
; {( i0 ]7 S4 S2 _ @ save = *addr;5 V! \& _: o& [; p( v% A a
sync ();* ~5 W- Z# [" `- V# V* C) z2 H0 x& u
*addr = 0;
7 F8 N0 G9 G, b6 w4 Z7 j1 R! x5 n2 O2 C
sync ();/ d( ? U9 Z% [+ J: I7 t
if ((val = *addr) != 0) {
6 a7 i0 A0 x4 U/ p# _- k) Y" u) A /* Restore the original data before leaving the function.
6 @0 H) {& B3 e5 f# W4 ]. I */7 H; \. ?" F7 x' W1 G
sync ();# }, {( M" \, M: m9 V4 w+ i
*addr = save;: J4 r8 g# J4 t
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
7 `- X3 P6 ~$ x, ]( M addr = base + cnt;
6 D p, b' ^. d4 y8 J sync ();$ [' t3 h* ~ N5 K# W5 c+ F+ u6 D" B
*addr = save[--i];* ]* X n D/ j; X# p' }7 y3 g
}
9 u. p i5 i. ]; m; e, M return (0);/ a- c! Z) I/ n! }
}
/ W1 H6 w- R$ z3 _/ @0 a3 S) t$ B5 p# H0 K; ^4 I2 l, U0 x
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
0 w& t6 m R% [* [: R addr = base + cnt; /* pointer arith! */
2 g" v. O5 P9 \0 `, P- S val = *addr;0 ^* W' ?* g' i/ F* m- s
*addr = save[--i];
0 F: u. f0 k p' t2 Y" s if (val != ~cnt) {
' V0 l" |( z0 {8 { size = cnt * sizeof (long);
: n# S. C/ Q# n$ _, }2 ?+ k5 N /* Restore the original data before leaving the function.
' ^$ m5 y( \ b */7 P2 P3 X; ~" ?, v1 P
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {4 S( x5 Z6 r: E
addr = base + cnt;; P K, T L' k* r' k' v/ }
*addr = save[--i];3 v8 Q6 Y1 W) A
}7 m: M; y) |: l- F9 L5 b+ Z
return (size);9 x" Y* W. i* r: n# d
}7 y) F' w# y7 g
}
, c1 F7 ?: m4 I& m" N i5 B" d9 `2 W5 o* l
return (maxsize);
. |. U& Y3 e5 l0 u& p}3 w. Q+ F, S z+ J7 |. T1 T) ?
int dram_init(void)
U& g5 ~! X3 P. K! ?{
% p% ^3 n1 ?' A" a4 R6 q8 ?' W /* dram_init must store complete ramsize in gd->ram_size */
& ]( V; P& D* l# y gd->ram_size = get_ram_size(
3 y0 [. e" Q7 f$ s- A: f2 V! N (void *)CONFIG_SYS_SDRAM_BASE,- C7 x+ k3 T4 _" b, z% p
CONFIG_MAX_RAM_BANK_SIZE);6 c0 H0 a. H z+ n, y+ A8 Z5 V q) P
return 0;
7 X- Q" V# L" G3 @- q2 W% j}- p0 ^. ]6 |. e
3 l* c/ b8 L4 |: B& f9 W# ~
8 K. n3 D5 c: b) a+ d) B; l9 |; H
- `7 b5 |4 W0 u8 h1 a0 S
( c. z6 ^$ v6 J$ x/ q8 b- y. k7 B2 IFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
! c5 n0 e6 g! L$ }+ c& u1 ^/ V1 H7 m
( }; K' ~0 ` E& J' |6 S
( k. |# H+ E( \4 o: U |
|