|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:# V( H x6 S0 B* P l h
/*+ P5 u0 b: Z3 x! M3 b& f
* Check memory range for valid RAM. A simple memory test determines
% w) w& n! z/ M3 k; i) T& |/ L, L* the actually available RAM size between addresses `base' and( e. D* W# p3 \# g' B- `; a$ M
* `base + maxsize'.1 a1 M4 H* U6 g: Y* ]3 O; u
*/, X" J/ x( [% k1 o: p
long get_ram_size(long *base, long maxsize)
! j- d3 R2 X; C0 g/ S3 |% H$ b{
& U5 ]" G4 h8 T! V7 P volatile long *addr;3 f5 V: J, b% q- B7 ?, a
long save[32];- n# ^9 |% R f# {7 v
long cnt;
1 a2 R% \, p2 q @/ M7 y4 J6 D/ { long val;8 S) c9 P: f, a1 i! q; W
long size;
4 q4 a& b: z3 T, B3 ?8 W2 t) u int i = 0;8 `) U8 {2 u: V
, V5 E5 R; ~' W; K7 Y) h2 r3 c for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
" e- d6 r, E* A( q. u7 T addr = base + cnt; /* pointer arith! */7 b* p' P" w: Y' q. q, V
sync ();2 Y- M6 V! e$ ^ {
save[i++] = *addr;7 }: i- L+ O1 L% C6 C
sync ();
6 d! m- d+ o! \4 A/ c) H *addr = ~cnt;
; o# c) C e4 F* h" O, w6 O }6 w$ o/ S; J( n: q; d
1 O$ A$ W [* K4 P& |
addr = base;* d, H0 h2 K$ k* z- J
sync ();
. E. h: J. W+ Z0 _: D save = *addr;
. ~( d* z& W' Q2 \4 R- R1 q sync ();! c: Q* n5 b; H( @! J9 @! g
*addr = 0;# h* H; w+ ]- Q7 Y
) o0 [/ S3 ^; D: ? sync ();
U$ k0 s7 c( V. o2 b" s* { if ((val = *addr) != 0) {
# w2 a8 `5 R$ w! }% z /* Restore the original data before leaving the function.8 u% v/ H3 \$ M( X% t
*/5 d# I5 n, S4 o2 ^( G& Z: p% R
sync ();8 |+ |; d# s4 H& u- }
*addr = save;6 I4 |# O5 m! K! S$ k& V
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {' q# L; Z) ^! p( h; ~! n
addr = base + cnt;
# G6 J( x+ F; F- [4 j4 m sync ();) c3 r2 d: `6 E7 j8 P
*addr = save[--i];* }8 Q2 Z4 V8 I! G# a4 q
}
: ^* e' R1 q. n% l: H return (0);
9 {1 q' k% S2 i9 A* D3 N# O2 D }
5 q4 {7 S8 J5 U( \( J( V
* ~: p, a% ?5 S/ \& ] for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {. }4 C! O, J) B( X, u
addr = base + cnt; /* pointer arith! */
4 ]: a& T% I4 t3 m" A9 ? val = *addr;
3 G, E, [9 S) P1 H9 E: J) n *addr = save[--i];
4 I' y& @% p, [. M$ T if (val != ~cnt) {5 S3 H3 X, ^6 \2 d
size = cnt * sizeof (long);+ U1 z) g# p' ]: T& y( x7 c, g
/* Restore the original data before leaving the function.: l! M. ?( e1 b5 U
*// c* ]9 l( H0 o
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
2 F2 _* o# C- r3 ] addr = base + cnt;
( t3 | L: _$ ]2 l( \ *addr = save[--i];' e; r$ U0 l% l
}
* v8 M! O* A: o return (size);4 c, {5 i1 U9 u: W$ W5 f8 J
}
( D$ U. M2 X) U: F' _' } }
# k6 c5 L, I* a2 i% D: g, |- {: s- E0 H- M, X, h3 S
return (maxsize);
9 M8 B9 x' j: u/ X}* {! }" r9 \0 P/ q4 v' A, V
int dram_init(void); v3 t8 L5 U) x; |/ {1 ~ S# R4 ]
{( e$ z+ q+ o- i' t( {1 q
/* dram_init must store complete ramsize in gd->ram_size */" O+ p2 M: b( Z+ a- n
gd->ram_size = get_ram_size(/ a- [, V4 z! E- m
(void *)CONFIG_SYS_SDRAM_BASE,: g" n0 X& O( D- t# Q6 t) P7 h
CONFIG_MAX_RAM_BANK_SIZE);
7 {& f$ M" Z5 i7 h+ t. I return 0;
$ ^) {% t) ?$ X) q% [/ E+ z8 ~}
$ W- h& `' G5 u" h7 p+ Y, `
4 J3 s4 p( B' ]$ ?6 J2 i8 d2 X9 ~5 J$ r; V* L! V
4 `) S2 J3 `* G" d$ }, ~8 u
4 M/ ?4 j. h9 i5 g @& x* tFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
" e" Z0 R; {$ v% y; |1 i
1 |, n/ s+ k) v; I- f9 [7 r t, P. m
G% @8 ?9 T3 g" |3 J
: i, { s }% g6 p% l" B |
|