|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:) y+ m, r8 J4 S' V I' H" w1 F
/*' m( F( b. f, B, ]* h- H) V
* Check memory range for valid RAM. A simple memory test determines4 y! g$ `, y- @' g: d. H5 F. f
* the actually available RAM size between addresses `base' and0 s3 V |0 L) i) |$ x- Q" K- _/ [
* `base + maxsize'., S) o$ j! L8 W
*/, T: P+ J# j# d1 D, c0 ?) Z
long get_ram_size(long *base, long maxsize)
" O3 }8 ^4 A2 B" `4 _- L( \{
; x( \ G* Z; J; Y( H1 J volatile long *addr;
1 Z4 L6 |% V" J) t7 ~; P long save[32];
2 e- b _. B; S, @ long cnt;5 B4 g7 k5 [% p% o- `5 Z* J
long val;
- v* \$ ]' U X long size;/ \! Z" c* g0 b5 o; ^. B
int i = 0;
* M5 f8 B- E+ ~
! Q$ Z+ O: z9 K, p$ b5 T% u for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
2 k3 U7 s, ?2 l* F addr = base + cnt; /* pointer arith! */1 v k5 p" J0 ?* ` ?5 G0 o% M8 K
sync ();: _( m' s# }2 g7 o; M
save[i++] = *addr;
7 l) K3 b8 m* s1 }8 O! Q/ F' a sync ();
' y3 ?* i2 ~6 m *addr = ~cnt;
1 p1 E6 s3 O& \% S* r6 [2 p4 a }
3 Y( H. w* k5 W6 `! L* o# O
/ \ l+ h4 p; L1 I addr = base;
; M9 |+ |( `! J+ W& U' H `6 _. _ sync ();
% t& D6 f' g' A% i3 T save = *addr;
/ Z/ e ] h6 m sync ();
1 g1 T# J& [8 Z *addr = 0;
4 X- U9 N# m F6 Z* k( P& `2 S; X8 u4 H' z( d* C2 ~) Z' R: I5 m* G# _
sync ();
6 H- J) d) d8 I( L% u, w if ((val = *addr) != 0) {$ ~5 g, R* ^! k) C! O
/* Restore the original data before leaving the function.( s V U, Y) ~
*/* D4 g9 o) X0 {, \" A a
sync ();2 m: G; x8 y* b
*addr = save;
4 S+ d& _% L; }: \+ N8 z9 P( g0 ~ for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {' P) p; [1 p/ X9 j9 q- X
addr = base + cnt;- t9 I0 E' l7 D* q9 n w; P+ y
sync ();
! m- ]& J8 o; l6 v" u: {6 P' X *addr = save[--i];! t( t: f9 x" a5 f2 x
}
& O" o" I! s: F% U# G4 U9 @0 y8 j return (0);
4 l2 f9 J$ k- O# H3 T }' J5 e' f4 t/ |( j- h
( a T- ]* }' e- Z! U9 x$ f2 ?9 I
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
6 y! h. J5 t+ L addr = base + cnt; /* pointer arith! */
/ m! x: B1 Z" D' Z, `% n val = *addr;1 A F6 b- E+ i6 r# c- t
*addr = save[--i];
) z. I* k9 h+ J" ^5 Q9 c0 b" k if (val != ~cnt) {
s Z# j7 t3 ^( V6 @; x8 N5 i6 Y size = cnt * sizeof (long);
& Z0 @7 f7 g9 }! b /* Restore the original data before leaving the function.
2 o2 t9 \5 L$ M* m */* A6 u: T7 X- ` O& Z2 M
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {) j5 i# o7 W. T
addr = base + cnt;. \$ l. g" v! Y* P0 a
*addr = save[--i];
3 H1 P4 ~2 o! {' y) D }
' Q4 }2 \2 \: j5 j1 R return (size);/ Q# X6 t0 p) R+ D/ l+ n
}
) U9 I$ w ]0 z4 v }
. I3 Y1 ~+ m4 X7 Y0 B8 P m. s' B' k& n' E* r9 u: F
return (maxsize);. J3 z# l( q! s* U. t6 q" X
}
8 M3 V+ S7 W+ Fint dram_init(void)- q. d$ w4 M' @; x2 q; N, Q
{* W4 X+ l4 o2 Z: u% M W
/* dram_init must store complete ramsize in gd->ram_size */7 H3 ~! \6 f& ~1 C& _
gd->ram_size = get_ram_size(
]1 D' D/ k1 `( b# s6 H# f7 H: r (void *)CONFIG_SYS_SDRAM_BASE,
% f2 A/ C9 Z. R8 J4 e) r c CONFIG_MAX_RAM_BANK_SIZE);
8 e1 ]6 M7 S: `* }$ J+ T return 0;
, ]2 }5 W+ J" f# ?5 v$ j}
( m; }2 T% O( d/ B' e
4 ~4 @* g* p( x* X; `% K: z1 c( V8 Y" H' _ L1 ?9 p G. v- F( o
8 P% J7 V( C4 X; l
5 y2 F2 e$ F' Q( S) M
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!& U% k# j# J0 J5 O
8 s2 e5 z5 R( t- n# h. S( @
* o; f% j- l# }# z" N0 ]! R" a
/ {2 x6 Z. ^" w |
|