|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:% g6 Q, Z; d/ k- p ?
/*
( L7 r, O, C% g) L: v; _* Check memory range for valid RAM. A simple memory test determines
3 w0 b9 C A0 S8 _* the actually available RAM size between addresses `base' and1 F5 L6 B0 E( j6 f; X
* `base + maxsize'.; U5 i' G: ~7 T' S
*/
; g) c8 C' U" |( zlong get_ram_size(long *base, long maxsize)* u% G Y7 g4 V6 }$ K
{1 ^9 b! s" f+ ?% [# f- S9 n% F2 v
volatile long *addr;
- m" R% \+ m# S* A0 d& e- E long save[32];
- P7 W. Z1 [( |. ? long cnt;
5 R, }, |4 e4 \ long val;% o4 Y; d6 y6 {
long size;) X$ D) ^/ N6 N4 E5 T" O
int i = 0;
3 f. M' ]8 C3 }9 Y/ e0 m+ _( @6 M0 i9 i, E& Y
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
% v ^0 O9 n" n3 u% J8 D; N4 z5 ~1 P+ i addr = base + cnt; /* pointer arith! */7 F9 L f) m. S$ u
sync ();; M2 Y. Y) p% \* Z. D5 w
save[i++] = *addr;* i# I- @( Z7 B, s0 U/ G
sync (); O5 x z0 G" O
*addr = ~cnt;. w0 o. H& ?7 y' W1 x9 t0 Q: w: K+ v
}
, X' ]* ^5 M Y v, n1 Q$ c( N G0 M" y4 {% p1 n
addr = base; Z, H$ a c# ^- J7 ~
sync ();7 F" }1 M+ g# Z
save = *addr;3 }; l) t' B/ c s
sync ();+ {) ^* q$ G# R5 `' r
*addr = 0;+ V+ Y8 d" O9 I) H0 C9 }2 x) {
( A$ e- N5 V: A8 W" i+ B- @
sync ();
# `6 a7 A7 |, n. P0 f5 d' j if ((val = *addr) != 0) {* e' O" m: }9 _) L
/* Restore the original data before leaving the function.
& W, O( @- {5 Y+ J: o, l */
% q$ \, b) F; |* { sync ();
9 A3 @% F# W$ }0 {. s/ ` *addr = save;
: A1 y8 F2 @4 l0 m: d! T- t for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {2 z1 ]+ i, z5 K
addr = base + cnt;
/ n3 B+ W9 j( w" Z$ n) v- G3 p$ ~ sync ();
7 c, c: J# Z" i ~3 s% D* z *addr = save[--i];
" t, ~, c6 q: m }3 q6 N1 {' L' Y6 g4 N* [
return (0); K# G9 b; R* { R# B
}# X/ |% T$ O' ]1 W# A
2 Q; }/ t! S" T p7 U
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {1 @1 D$ l4 n+ W/ `0 S
addr = base + cnt; /* pointer arith! */! F' C9 q& x b. O5 D. o; A( E
val = *addr;
4 x& W! I: g3 \3 `' ~9 N *addr = save[--i];" A* o3 E7 [* u1 ?3 v W) X
if (val != ~cnt) {; i2 |- ?- V/ C* I4 i
size = cnt * sizeof (long);- `. m h1 n5 V/ g4 P: j
/* Restore the original data before leaving the function.5 r) D* t" V% h% M8 y
*/
* p( d- e) n$ S" z/ x for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {2 o5 t- j$ ]0 F! @# L+ ~$ i
addr = base + cnt;; ?& d! L3 T0 _# o& E: I
*addr = save[--i];
3 ]* h" G' y) y1 b- F+ e }
. H# F# F- J! \8 B return (size);
* G8 H$ h2 j, J/ `8 q3 g }) j1 g/ p8 @3 Y- t
}
( P& k* r: ?0 U( M/ }
6 ]5 t- x" R/ O5 n, ] g return (maxsize);8 B9 b1 ~! j4 ^& G5 F4 y
}% b3 ~5 J! G0 G, p
int dram_init(void)0 j* r/ o4 n" m: } x4 b: K1 V
{% w, D. `; f) @
/* dram_init must store complete ramsize in gd->ram_size */) h2 q" l n) h# n# o. N
gd->ram_size = get_ram_size(+ o1 j) Q6 o6 `, b; B9 P% O( D
(void *)CONFIG_SYS_SDRAM_BASE,2 O6 Z1 L- R2 b, j( V+ m. ]* J; g
CONFIG_MAX_RAM_BANK_SIZE);9 x- h- m2 }5 v8 M, {* U
return 0;: Z* N' w. k) e+ p
}4 {! e* s/ \& g# L$ ]
/ N. V- z0 w' b6 i# g4 z; g; @
) Z3 M* |$ ~1 y" q) O
: R" _. k8 g1 x% P9 o
% i. P4 _7 c' t! q' `: XFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!' _! b; Y) Z- q h" s3 g. D# H
! W3 G3 ~& a* z, k
! s, m# M( s" q: V: D
1 O+ Y- N" w; M# E |
|