|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
5 I0 I1 a' V: R2 B" l: E" k ~/*6 w- ~2 U0 T9 v2 i4 W6 B
* Check memory range for valid RAM. A simple memory test determines
, }3 _. F7 i, f; m' q* the actually available RAM size between addresses `base' and# Z2 Z4 {7 S" k! L( D
* `base + maxsize'.+ y' q2 o+ {) p, a6 T* T% _
*/
8 j3 {8 Y0 U; ^' d: X. Zlong get_ram_size(long *base, long maxsize)9 ^& j# I, Q* F% ~' o8 E; `! j
{
3 G& R# h5 {5 ~" x+ P. G7 i volatile long *addr;
. `! P7 L' T) v: Y) u# t# V long save[32];
, S& H5 }; a5 }* e long cnt;
- \+ n3 H5 A" ~5 }. t: Y5 x( f long val;
+ |2 Q! [) ?7 Q1 s. W* E7 w long size;/ b. t! j( a2 }' C& @
int i = 0;
# Z. E; W! @/ @2 ^# \+ _8 }4 S$ J- V) N, ~) `2 }/ R4 p
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
& L- o" M3 W0 M4 g5 ?& M addr = base + cnt; /* pointer arith! */2 v9 `. @' I* ~0 \; T+ U
sync (); L9 u4 A* c6 l0 f
save[i++] = *addr;* D. G6 \) _, S0 S
sync ();" f O6 x5 h) j# }" q
*addr = ~cnt;8 _8 R4 f3 ~1 w' S9 f0 x
}1 l9 p6 S" p" `) q$ O, C4 k' f1 L
# r, S! o; K0 X% s e6 V, r. R+ m
addr = base;: [; }; I+ [( P8 R: V! D
sync ();
, F8 R/ P `. m" S; A2 } save = *addr;: A8 t7 }& T4 Z2 h" O: ^. ^
sync ();
' L* L* b4 U; j: E *addr = 0;
/ }9 a+ ^% ?# ~* n* j# P" d* t3 p' S; ^. ]1 B; v
sync ();3 B3 [6 |: B' u' F) A
if ((val = *addr) != 0) {
$ |/ K5 i8 h1 V% Y/ e /* Restore the original data before leaving the function., \* h$ _. D' I, A# O( W
*/9 u5 O5 G1 }# d- o' s
sync ();7 G3 |- G$ U2 p
*addr = save;
! n1 ?7 ~; ?* a2 ]9 N for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
+ `2 k" x3 a# s6 s1 p! s addr = base + cnt;
' F) |' W* e* n# f" B' X1 ]; g sync ();
8 o+ Z; n9 B$ z9 I7 W9 l/ D5 O *addr = save[--i];
! v1 _* S" C4 D/ `) b. [ }
# [1 Y" u$ [& D return (0);& k7 k# i3 T( @
}. h' J0 c# `6 E% a e
0 r; |" O" q, i/ m% C6 ?, p
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
5 y4 S% r# _/ p) L: P5 G# x addr = base + cnt; /* pointer arith! */4 A$ C# y8 }4 V0 N2 q0 ]
val = *addr; F/ E# y& f3 P: B J' l& Q4 p
*addr = save[--i];- L+ w- q2 m3 K2 K
if (val != ~cnt) {2 r2 T, a7 w( N
size = cnt * sizeof (long);$ g) n% S* N1 r7 ]- P
/* Restore the original data before leaving the function.
8 X& T' S- I+ [ ]7 I& c */' D; H% j" Y- ]/ s' k3 A7 ~5 W
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
* ~0 r/ D( Q+ A* K' k% u" G; f addr = base + cnt;: m) ?% a# d, a, N- d/ ?) u
*addr = save[--i];
3 c3 }+ v( N. T$ c* ]2 I }% w) D4 R5 @- R* L' @4 U
return (size);6 y4 F/ l; G- }% T6 k+ @
}% d" |% ?) G: f
}% y* X$ H1 q; d1 G1 t5 w
- g' u2 z: m" m D
return (maxsize);
. W1 }5 Z2 d9 e* u}
* e* v2 a) n. eint dram_init(void)
0 X G/ k' k: m+ H" [{ z0 n7 F' R! p( a1 x
/* dram_init must store complete ramsize in gd->ram_size */
# n4 ]+ a; c; u" g! c gd->ram_size = get_ram_size(+ Y* M: U, _# D1 t/ N" v. E: l
(void *)CONFIG_SYS_SDRAM_BASE,3 B ~% x" g0 c" V
CONFIG_MAX_RAM_BANK_SIZE);
6 @, v- X g3 J3 `# T' z return 0;0 p9 i% w; E' }9 Q, [
}
9 i, H2 `2 b" J- ^' A) r# i( i! K R# O
& Q# v, _2 C3 h' O, t4 q
) w' W$ v; Q7 K& e% w4 \! b+ c
7 @+ @) n; H6 {$ c2 E$ X, RFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
+ ?+ ^5 f: C8 X) R) L. ~% H" n7 F1 V% u1 z" h: O) `! v8 G
}# D4 H$ y) y$ a+ s( _6 y- e# c9 h( C8 ?( ]4 A; _$ l
|
|