|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
6 b3 b+ c* G$ a. f! `3 M3 E( b/*
: e% X& L: ?3 ^& C* Check memory range for valid RAM. A simple memory test determines* Y; l6 R8 h) b+ E' v) J
* the actually available RAM size between addresses `base' and. _) i& ]- P6 s- ^5 \( V
* `base + maxsize'.
D) k: {. |: D9 v* h* V0 v9 X*/& ?+ c$ k* C- F8 K( \8 t$ @- {2 {
long get_ram_size(long *base, long maxsize)
% V4 P X9 A; u9 D& d: X{4 F- m2 a" t q; f6 @4 o( i2 H8 }/ l
volatile long *addr;
" B' m4 {% n% T/ h. U$ u( J long save[32];
7 B6 f+ h- \* T7 @7 Z2 } long cnt;" ^/ W% y3 c' g+ o) k6 x0 Q, k
long val;
0 @) W9 u: l' G* m& p9 a# _( ? long size;" }& G) F! D" }
int i = 0;
& Y$ ^- @9 S; J# G4 a; v! {: @; R5 L# r" K, r, s
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {1 X+ W z1 G- @0 }
addr = base + cnt; /* pointer arith! */
* E3 s [7 X: h$ v sync ();
5 b: Y9 \; U1 c- ? save[i++] = *addr;& a$ W& ^: F) ]6 R' U
sync ();. C$ f" K8 m9 c4 D$ d
*addr = ~cnt;
) R$ [% l/ Y) Z `1 d/ h* B }! @6 X4 Y" v! C7 A- j# }
0 W: x7 e# b! B s7 R" U* a5 D4 }
addr = base;
& E1 R7 k, @" s8 V$ J* w sync ();/ e X, P9 }5 K9 a* _9 x8 |
save = *addr;
, I+ G( e) r5 t: o3 X# @ sync ();* A3 N3 f0 {$ o. [" @
*addr = 0; }. Z3 S- o5 L/ w9 d" M! i) |2 i
) b9 ]) A P- y+ |0 q
sync ();
# Z& @" t+ C" C; m% ~1 O! n if ((val = *addr) != 0) {( L% t3 q8 c) |# ?' I( b
/* Restore the original data before leaving the function.
1 _, F- ]% o. o. b j$ j */. `: F9 X' t: R, o7 `
sync ();5 l' ^* Y) N/ w" @7 V+ t4 m
*addr = save;
- \% I/ z* v: v2 ~ for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
- T) w4 @7 N( j8 P0 q addr = base + cnt;+ s& q- p/ ~# k/ w' u( u' Z* m3 j
sync ();
. m- O) _& P$ X4 g% o. e5 | *addr = save[--i];
% Z3 `. o( g/ Z8 r% ], ~* r( e }
2 b. B) u3 p' E2 W1 H3 j return (0);# _5 o; o# V1 ^2 Z) T6 ]
}! P3 q# T8 C/ z/ X: f- K
& ]/ L& s% K* A i4 ^4 n* O for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
# q9 @* E% b& c% Z4 v6 x6 N addr = base + cnt; /* pointer arith! *// W7 C4 } s. D# O5 d- E) y# Y
val = *addr;% D' R5 C& }( X- t" }% f
*addr = save[--i];, N' j# }; f# [
if (val != ~cnt) {
& c( Q1 i! P0 l/ A: A$ ] size = cnt * sizeof (long);
9 `9 P* M7 k$ M5 v3 H# Y /* Restore the original data before leaving the function.4 N% t% ~) b1 Q* y$ X5 E
*/" Z: s9 N0 o& c# }$ x9 u& d
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {$ \4 U8 q2 m) t( k! O2 p
addr = base + cnt;; `& c) E W; ^. Y W* K4 b4 W3 H) D
*addr = save[--i];- m: v5 @4 ]$ V, `/ I: n
}
. Y+ J# i! x4 T/ H3 i3 p return (size);4 U6 d. W3 u) ?
}
3 N; Q& C$ D6 S0 j; I7 B4 W }1 g8 h- x" E& b) V% b6 t
; z; `, E" H: _9 G5 C
return (maxsize);4 L" L# x9 f6 @
}2 `: J4 g& G, d7 V7 R
int dram_init(void); M& s2 E# n# C( x9 z- {
{% g" x) N k. j' _, o8 M
/* dram_init must store complete ramsize in gd->ram_size */: p J7 w' [: m) y9 o' x
gd->ram_size = get_ram_size(" B& l' f I! R9 ~- G/ {0 c8 P
(void *)CONFIG_SYS_SDRAM_BASE,
- Z6 U6 t9 }9 H' f. f+ o CONFIG_MAX_RAM_BANK_SIZE);
; h/ a% b' u4 s# O: y return 0;
3 L) ~0 L9 a( @0 V}6 T6 L* F2 p2 f& a2 z1 p
5 ~3 g6 h3 T5 J2 G# a$ ~( u+ D
: E2 |! B: o, |: H9 W
% I) [$ D6 p* |# v/ Z% n8 b
$ d4 g0 m" m0 R8 P* `
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!* M$ H6 L# [ ~# ?8 M; f
" Z( z3 l; O6 [6 I7 r6 v- |
: a) B8 |8 J( A5 ]
. Y- S, b S7 n' @, y |
|