|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:) e5 s* \( W+ r* a- z7 q( ~2 e% P; B: V
/*
: t' _1 g4 ?5 w. i0 B- S2 U* Check memory range for valid RAM. A simple memory test determines; r$ p. P; A/ A& J4 j$ Q2 D
* the actually available RAM size between addresses `base' and
+ M3 l. Z! U3 J4 q9 k" }% B) K* `base + maxsize'.
& g2 ~* e% t. k8 e1 Y9 C2 P7 }*/; I( R; |: |# Q9 w# `! ]
long get_ram_size(long *base, long maxsize)/ l( D8 f, ^ s8 T1 J
{
) {+ g) i D2 w+ a volatile long *addr;% v' e, x6 E {! m, A3 q0 L$ Q2 X) I
long save[32];( U5 K P8 `) n9 R, q
long cnt;5 M' T6 U- T) p( e; i$ c2 s
long val;; k# i! h$ n! W1 d( {3 `# ~
long size;
; O+ ~! D5 E0 \; j' W6 Z# Q; Y int i = 0;& [& r3 G+ ?, D; e
+ g% S9 `, W- ~! R$ w3 L; _ Z3 Y
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {9 `8 ~- l- I8 `; I" f$ I; V! s
addr = base + cnt; /* pointer arith! *// r, ?5 }$ a% t+ {* A! l
sync ();. r& `1 `8 p) G2 L$ i6 D
save[i++] = *addr;, R9 a* c! S, H
sync ();7 P! ?6 b* K1 }
*addr = ~cnt;
8 x7 x% p& S6 m4 y }2 w) }! n( q, h; Q# J/ W W
, N$ E( ^' m7 g- G7 ]# G; U
addr = base;
3 D4 }% @ @8 B/ m# i9 x sync ();! W/ J3 U5 {% M' T( l
save = *addr;
& A; d- o4 D a+ N8 q# C3 n sync ();2 q7 i& k$ _) g& e) S( B" ?; ~% i/ y
*addr = 0;
$ }; D; u0 v2 I1 g
+ V" j [* L. e* B2 Y sync ();* J& J: `; s% \, s' u+ U. n- F
if ((val = *addr) != 0) {7 m/ k3 j* _# f& s7 Q9 O% R8 b- t& j
/* Restore the original data before leaving the function.; n. G0 G, [; ~4 ?
*/) {' f/ G1 r- D$ ]# M
sync ();: c2 n9 o( K. n; B" ?
*addr = save;
5 Y2 K0 f. E5 b3 k2 U7 P' T& B) L for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {5 Z$ p( O J. S% c; J
addr = base + cnt; c, H, o v4 X* _, G6 Q2 G
sync ();2 _9 R3 f3 G2 n1 \. c
*addr = save[--i];
# r8 n @1 c8 F; Q0 J; d9 j# P" _ }( L5 K7 T8 h, ]- a" I8 b
return (0);' _8 T# h; I/ O& Y% t$ B' f# Q
}1 ]0 o# s) y9 B" N
# _9 q+ s, }+ |, J4 I S! ]4 a" z; `9 b
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
2 n; U6 C. l9 p, O3 c/ s* V, ~0 ?; o addr = base + cnt; /* pointer arith! */
9 t$ P1 J( m, `+ \& _" f! V: F/ ^ val = *addr;
0 S$ J: c: i& ]! x% h, E *addr = save[--i];
# [' @$ c0 f$ U3 L if (val != ~cnt) {
/ j g3 U! J( t c& ^4 t3 F8 M size = cnt * sizeof (long);
8 _' f" \3 _( O# s5 C/ | /* Restore the original data before leaving the function.
% u8 @! e0 I( ?/ H, G+ `( t */6 u6 g, n- k( K1 E+ @
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {6 {7 l1 \. E' T. Z- M- Y
addr = base + cnt;- e2 [5 H: p: o4 k( s" Z
*addr = save[--i];
& q3 q( _6 _, s. |: v3 n5 Q% U9 F! b }
5 w: _+ y4 ^9 p+ h: E return (size);
, q8 r" Q% j t! `: V5 ], c. g; A }
& p* G5 L# x. l, ?4 R) ]9 \ } I: a2 m, P& H, O$ u' z
3 K9 h+ |& E7 W6 T5 ~: m
return (maxsize);: d. J6 Q' K2 Y5 e) \: P1 y5 f* n
}# r8 c' y* Z& x1 U2 w
int dram_init(void)( T# D! _1 t9 |9 n
{, D9 \# C0 E# x6 H0 Z6 x- Q" i$ `
/* dram_init must store complete ramsize in gd->ram_size */, ^$ P e1 H' K# w6 x/ D# h
gd->ram_size = get_ram_size(0 M* ?8 {+ b2 b9 M2 T1 K9 t
(void *)CONFIG_SYS_SDRAM_BASE,2 @0 m" E$ J) X0 w+ {% T
CONFIG_MAX_RAM_BANK_SIZE);
3 r# I$ t( M# q! K8 `7 G6 y3 { return 0;
& v7 Q) r( `0 R7 w}
- v- ^* N# V3 S0 Q$ b6 J$ S+ J/ V& M' D7 u
1 ~- s9 @6 W- R5 ~& v& b5 w, \
- }# F" p$ s- l& e+ J$ {% G3 o& L" _0 `( Y4 D f
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助! u t! ]) s0 O, w
; N5 _7 F7 i/ w+ X1 u9 n8 V3 l$ g$ M+ f
+ w6 p! U6 f. q; v |
|