|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
- N( f X7 ?; W( E0 O/ Z9 L% G/*
6 e7 R: x* Y" k* Check memory range for valid RAM. A simple memory test determines
( Z& j* t# ~. y- C( q) v* the actually available RAM size between addresses `base' and
' g* W, M' W$ h V6 y. ?2 l* `base + maxsize'.2 w3 [# Y* D; ?' Y
*/4 |2 z- I$ T y
long get_ram_size(long *base, long maxsize)3 ?$ z& Q2 Y# p3 Y% d; R
{- v# u9 L5 g& C3 K: g- b H
volatile long *addr;
5 j% U7 A: S W& q; c4 |1 | long save[32];
: G j$ f2 w& h- V long cnt;5 m+ P$ x1 W. e$ D1 F* G! }* `2 A/ h/ y4 B
long val;" _6 p) E8 a9 m# m! l7 o8 Y
long size;4 W8 B. n! m( G! N. V- ~
int i = 0;% b& F, @# D4 w, Q; Y" x9 \
' r2 O2 v2 O- v: H6 v: j u: H for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
- _2 l# p; b4 z5 t" z* w addr = base + cnt; /* pointer arith! */
, y8 Y1 ^0 t9 h; \- }9 |% ? sync ();
, x5 m- I7 S% g- L5 x save[i++] = *addr;
# V% \) ?$ E0 r" B% C% H2 _ sync ();
' _9 L2 \1 t% v( y/ ?3 ?" g- W *addr = ~cnt;
) f3 g7 ]+ d; S5 j8 A }. C$ N3 X! J" O) n
5 F8 `! n: ?- x- N. B; O+ d, e4 X
addr = base;# f. \9 f# N1 V
sync ();
# K; {8 H# Y1 ^2 W' t save = *addr;
/ T; q. i" V' z sync ();+ S& E$ \# E. V
*addr = 0;
" w: M J$ M/ }# y& w( e* k$ D$ l& @. l ^0 |: `: h; ~+ F
sync ();1 B: d5 W+ @1 A5 R
if ((val = *addr) != 0) {
# ^' [' Y: |. j /* Restore the original data before leaving the function.$ z- q W b2 ]% I- K h6 `
*/, X* A( C) E1 C2 V/ S3 |5 \
sync ();3 p* e, @1 _, o, r4 l
*addr = save;
; i! b2 _) O( ] for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {0 ~$ E( ~! l5 f& ?5 W
addr = base + cnt;
8 ]9 s# R; y5 z% { sync ();" Y" ]7 Q" B6 a, I' t$ h
*addr = save[--i];
, h- F. [3 Q% f% V% p" g9 a+ y }
4 f5 K; h7 f# Z% E) W return (0);
4 [9 I: D1 b' T( V5 f2 n }9 z2 g+ F* {3 M, m3 ?" s' C% g
3 O* g/ d- \- M# H: z' x2 y
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {: C; B/ I$ o( o$ f
addr = base + cnt; /* pointer arith! */& d9 I4 O5 h V" E/ J+ T5 T
val = *addr;/ O) S$ [/ @. t/ `- L3 [8 \* F
*addr = save[--i];# M3 e, ]2 G) B7 E- ?& t* M
if (val != ~cnt) {
8 \% J+ Z9 K+ E3 z! a3 { size = cnt * sizeof (long);9 ]; E {4 M) T0 Y
/* Restore the original data before leaving the function.
* z5 L; W; I3 H* N: A */* x- E8 `! K0 F+ `& k; U. B
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
! l! s, ]& V, n. F8 Z$ }; ` addr = base + cnt;
\; m& @1 i4 X6 a* a4 i, \ *addr = save[--i];& w$ H+ I, y5 a8 ~6 d; H) |
}7 F$ F. V3 y- G, i: Y
return (size);* S z$ o+ h6 `8 L! v" Q- v4 S
}* D+ ]& m6 Z+ ? P. R% \
}6 q; [+ e* v8 s: b+ [
2 X0 Q5 l2 r3 q return (maxsize);
' S" C( }/ ] h0 j} P3 x( f- o7 j
int dram_init(void)# ?2 f# s$ A+ t& r. ^! s
{, A. W( q0 K% k/ W6 j4 y
/* dram_init must store complete ramsize in gd->ram_size */
# l9 R9 o* u, v% b gd->ram_size = get_ram_size($ |- P' h( B; S* O+ s
(void *)CONFIG_SYS_SDRAM_BASE,
6 d* c' p6 C- ~" x: z$ M& f CONFIG_MAX_RAM_BANK_SIZE);
& C ?5 y# B& I return 0;# T) s! H% [' V' V0 D8 O
}/ Y2 q0 j7 T0 p! E
* f( s# m, r; J/ ~8 G E, s1 W5 g
# r d' h8 S3 P- H& r* [1 { @+ E& I4 w; C. c6 |
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
6 G& g& A1 K' ^ F* p7 u& w
0 n8 `+ v# V2 R% R# P
8 }' Y8 d, c6 a; f L. r0 ~$ p$ A. P( g) b; Z7 ]) I! C- I
|
|