|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:! S+ I1 r( c* k( G2 I* z
/*
1 N3 C* G, ~ u& e7 W5 x/ D" q, a5 Z9 ^* Check memory range for valid RAM. A simple memory test determines
% a3 u; [+ p- P6 p+ s1 X3 M* the actually available RAM size between addresses `base' and( W6 B+ H: w- \8 c
* `base + maxsize'.; j9 X" d2 O/ P0 V
*/5 [& R- U1 i3 L l; u* K! Z8 W& }
long get_ram_size(long *base, long maxsize)
9 |4 O' q1 \, S: T; s{& k: F$ y7 }; x5 \
volatile long *addr;$ Y; [4 v; w6 h) O% k9 S& i4 d7 ?/ r
long save[32];
9 {2 K* \# @/ t, ?! y2 f+ R$ x8 t2 g long cnt;, B% u, Y4 j; i! @* T" @5 b
long val;; J) o7 B: g0 w; {3 C" z9 j
long size;
2 E1 J a( c, S5 p0 I: |* P int i = 0;# u7 |+ W+ M- }. I, ]% o Z) W
7 r+ |; c2 J8 O% d. U& o
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
2 B% d0 j/ h7 ~0 v( M" t9 Y addr = base + cnt; /* pointer arith! */, R0 X2 g' e, y$ r! d: [
sync ();/ O& g' {- Y* `' H
save[i++] = *addr;
$ n, H4 A$ ]- ?% T sync ();
" V9 f' e, a2 f6 s) t0 v" e *addr = ~cnt;1 T. h ?6 O3 j! z
}
# X% L5 k' o3 v I* X# y( O
% D5 Y1 c7 ~% U addr = base;
: Z; L; K! k+ l8 d1 ~ sync ();
) Q8 S% D V" X! e+ [8 J: r save = *addr;9 C% ^8 v6 Q: {) R# w( w7 k! I
sync ();
7 e& w6 l H) l' ^. M+ R *addr = 0;
5 t/ J- G2 j, B
* u; ?0 M# t% S- V, U sync ();) Z0 Y( c) l/ C/ a3 S: U
if ((val = *addr) != 0) {2 g l( `& G8 |; c& ^ u
/* Restore the original data before leaving the function.
; k5 P0 l. }* k */
/ m- Y# p! b+ n sync ();
7 Q, M+ n, K: u *addr = save;
! t( g& n5 U# K" h2 v. m7 G for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
) Y* u& m: ?6 x- g/ y addr = base + cnt;
/ r d& ?: d" ?$ c- Q sync ();9 F! G! F- m9 J& J
*addr = save[--i];& D+ b' ]$ _" \# C" J
}
5 Z' C- W4 ~' j& d' T1 g! _ return (0);8 f+ G, ?( H$ R. U
}* n+ @9 w- ?6 j' U6 |
( [8 D' Y" b5 s, u2 X
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {, d) J+ h8 W3 r" z1 |( v
addr = base + cnt; /* pointer arith! */
( r9 [2 D! ]2 z! F7 N e# q; S val = *addr;" s- b1 a# Q! ? y
*addr = save[--i];
6 Y4 [" w3 a# K3 @ if (val != ~cnt) {$ t' B! Q6 c# S! Q2 T
size = cnt * sizeof (long);- @, ?3 t0 V1 u: r! o9 q
/* Restore the original data before leaving the function.
5 h/ }4 `- n: D8 I1 k9 q */; c* P3 o7 F- p0 u
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
/ @* ~% w1 w- C( I; q4 b) t9 S addr = base + cnt;
5 b6 h9 X/ b; ^5 J5 g) r, a- h *addr = save[--i];
4 ~5 F+ O' O% z) K5 L( K# L% t }
8 q1 ~( O n% _# j! S9 h return (size);% z1 v' Q2 C& K+ l$ X3 [% ~
}
0 T; Z# E. s4 H2 w$ W4 C }
2 ^* Y2 B* X0 D! R" W, d: A7 l& a- ?' H7 a r+ \3 ~, ~
return (maxsize);. p& d! K: C( N# h6 h
}
6 a! y2 y) m6 M: c1 F! O% Wint dram_init(void)
( f) B& v5 }9 I7 g2 S{
u' R5 k$ \" w/ p/ A* p# U" d4 s2 n /* dram_init must store complete ramsize in gd->ram_size */
0 i5 Z/ n8 _+ j% L4 o7 f( o* f gd->ram_size = get_ram_size(2 F7 V5 P9 T! X" S8 G+ Y% v
(void *)CONFIG_SYS_SDRAM_BASE,
. s+ @/ B# c$ C4 G2 Z$ M CONFIG_MAX_RAM_BANK_SIZE);
9 t2 U/ z; U" b; v. M1 F return 0;
2 @* o! l6 ^: y( O}
; \, n A# R, N+ S
4 E/ z6 I% b3 R5 g, o. f- ?3 @ r+ @( _7 a+ O/ Z7 ]$ h
, {: k* n% p9 `! ?8 J. A: V3 H
! Q$ Q$ h% T% k6 j
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!+ L3 b+ ]) _' g. u( B/ U
: T3 W0 W3 t. P5 \
9 L- D, ?& X0 Q3 R8 \3 D" A
/ {' F( Q! j& @, [0 B |
|