|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
$ y% T1 J8 @$ Z2 c$ M, ^1 s- `" Y/*
- y r8 ^( S# D$ b" |5 R2 ]* Check memory range for valid RAM. A simple memory test determines& _4 o9 Z3 O! \2 t4 w# k o
* the actually available RAM size between addresses `base' and$ y$ f1 P. F* B; C! V, u
* `base + maxsize'.
5 ?% H' I! K8 x# J*/
@/ \$ w2 x, F% Z- D% d W, }$ Zlong get_ram_size(long *base, long maxsize)
2 B9 L2 a2 [( ^6 U2 v{
6 n8 S7 c& f. |! Y; Q+ i5 F$ t volatile long *addr;5 n; i+ [" k# F5 q
long save[32];7 s" J* i l! f3 N, p1 y1 \5 g' E
long cnt;
t; E9 O# d5 c. U6 ~/ Q6 x long val;
; v6 X. b j3 f4 ^! L6 B3 ` long size;
" M+ y* } T) U, }; _6 } int i = 0;# x6 z# Y) G! H7 T7 s2 s3 V0 w
7 j& ^9 R- y4 Q% g' x for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
e1 W* @. t0 e! Q! j+ V' c- Y. ` addr = base + cnt; /* pointer arith! */
4 {# ?5 P8 S, u6 k* v2 ^# z sync ();
7 f, q6 s7 y0 ` @& R: h save[i++] = *addr;
, r8 F2 \/ j1 d! U8 e2 i sync ();) M7 _- l2 q5 J7 T: W
*addr = ~cnt;
0 V# x ?/ T9 R9 l. \' C! p' j1 G T }0 ^+ g+ v0 j9 J, H& U
- k5 m2 A2 M6 X5 y: t addr = base;! P9 f% ?6 H# E" v9 {
sync ();
* Y) v& U: A! [5 |- y. J3 Q& @ save = *addr;
" k' P& M9 ?. F9 @+ K sync ();0 J5 o$ N# z9 ^/ [+ _5 A% E) w
*addr = 0;
# c, a4 J1 f8 v/ U- t. m0 ]' [5 Q4 G5 n
sync ();
, T# r! N: k* j if ((val = *addr) != 0) {0 u! I6 T1 t% `. m% w
/* Restore the original data before leaving the function.
. L- d2 H. O( R6 v# K: D! C */9 x1 W% u: }6 S! l! m
sync ();
3 R9 d. [1 j4 N *addr = save;* C+ x! E! ~9 P: a
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
5 V( o& c v2 V3 H: R7 y2 l6 x addr = base + cnt;
: f9 [4 P8 F9 G6 K- d sync ();
/ b8 \6 Z+ q% G8 y8 W( t% ?0 y0 ] *addr = save[--i];
& K8 A% ~' Y4 p- S }& O5 o+ m# M) p4 i
return (0);
7 \5 c$ O1 L1 z0 o* d0 Y }3 {! g% t. F4 m% x4 g7 ^6 |/ J; w
2 R: s( }5 f \& N6 l$ l for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
& e+ \8 E* k }3 O3 L addr = base + cnt; /* pointer arith! */
0 T+ C- B% u3 k, e) B: t val = *addr;
9 ?+ x$ p6 `# y y2 V2 R n *addr = save[--i];* q% L% Y: y5 Y# D9 y
if (val != ~cnt) {
( s. j2 D& L. A% o size = cnt * sizeof (long);
, b6 M- R' ^ B2 ^ /* Restore the original data before leaving the function.
) k1 b7 G* X: p8 A */, h# w% T) P, `$ g0 F; p
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
# {+ J4 W0 h, c2 |) U addr = base + cnt;
- p1 \' s9 ]. V0 F. ^2 r" v; j *addr = save[--i];
; z1 i% d9 s z$ _ D# h }! H" I+ x3 \3 P* f7 ]. S
return (size); [, G! B; A2 d1 N* ~
}
* O) u7 ?) l& p/ K: J }
% l) ]2 ?9 \, _5 V9 S' Y3 O" X7 e, w- t1 ^1 x: Z' P
return (maxsize);1 O4 A- m* a: r# O7 N) i I2 e4 u
}
1 g* U: M. Z0 N. tint dram_init(void)
# p z+ r) A& X& `6 F- R{( Z& q u: s# L |4 m* E" u4 G0 T
/* dram_init must store complete ramsize in gd->ram_size */ w% E( y$ t* Y9 X; ?8 c; C
gd->ram_size = get_ram_size($ ]" S0 S! s/ z$ O
(void *)CONFIG_SYS_SDRAM_BASE,
3 e6 v* I) I7 A- V$ f. A CONFIG_MAX_RAM_BANK_SIZE);, S! ^/ f, o" ~6 U* ~7 o- N2 T' V6 v
return 0;9 g0 y8 ]5 K% c2 [
}( |- T2 x, E3 A9 i/ y, r
0 T) `" T) l5 q9 u' P8 Z7 B' x. z" w
1 A$ S1 ]$ `4 O7 `+ Q4 B3 q: N9 g/ G
7 d0 X1 a4 V7 M% z2 W {$ o2 z
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
4 _7 d/ m4 h1 D1 p" X) T9 K3 C# z j# | d r& v
% R& [5 u; b' K/ Y" W8 A
+ f4 S! g* x2 |0 A0 Q4 e
|
|