|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:& Y% a& K9 t" P5 A
/*5 ?, U5 |5 k! @" D
* Check memory range for valid RAM. A simple memory test determines
, M/ y9 Y5 I* m7 g& n* the actually available RAM size between addresses `base' and! k3 y; {- [: n, S
* `base + maxsize'.* B7 ?6 R7 z7 n* Q; M0 j$ T
*/
) [& F+ X" W+ @/ L0 Q, Y2 Ulong get_ram_size(long *base, long maxsize)& K' S$ @ Y4 S& M
{, N6 J. r. c6 F
volatile long *addr;* f# a. f/ U. M7 b/ j
long save[32];/ w, _3 G9 x+ ]5 e6 q0 N
long cnt;
6 r+ c$ H ?2 l+ @8 M4 s" T long val;4 @% W: m' z) x9 V7 V" o) G1 \
long size;
$ Z! T, u5 O4 n, A int i = 0;
. i# C) w5 l2 N. F6 A, D9 A+ C6 `" R/ _' r* T" M
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {9 M3 y$ e# a( A1 r) T: R( X
addr = base + cnt; /* pointer arith! */
4 ~7 S l0 D. H4 h8 V N. t sync ();
- W/ n0 ^- m) Q3 [9 `# e9 C' Z, | save[i++] = *addr;
, K" ]) m4 ?* O8 q" r0 G0 {% \$ o sync ();
1 ~" K: S* ~( Y+ e5 d+ a" Z *addr = ~cnt;/ W/ l, L z' p, T
}
% R; N% L0 y7 a$ W
) i5 l$ h6 D5 i* |! P addr = base;
1 w D6 L9 G+ H sync ();
; _7 I7 t, y j) w save = *addr;
) M Y. J3 y$ h sync ();& ^" e! l* }2 z2 R a( U5 d! q
*addr = 0; p' m% d4 N& C3 Z- }
4 d) ]7 G n: X& U0 k( k: S7 g sync ();
. o* F0 B1 L1 x: f if ((val = *addr) != 0) {/ N( p8 ^4 C6 L6 P
/* Restore the original data before leaving the function.3 `; q* p# P/ A5 w( I% a: l
*/
$ a$ Y3 L- j6 v3 v sync ();
: e! |; x+ L' y: Q: U *addr = save;
/ N, h! U- E8 B/ {+ X" ~, r for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
n% p3 e! L$ }5 X, _5 o addr = base + cnt;
& [9 d. P- w) @+ Q( U7 o sync ();7 [9 i. z/ J ]5 e: e {1 ^+ K4 g+ H
*addr = save[--i];# ]9 U2 t, c: Q9 a9 g
}
+ ~; q8 A) d6 a4 h o, U return (0);
" m x' W* i, m, l, r+ x }
- _" y9 ]' L8 X/ b1 R
: X0 w+ Y& d( t3 Z" i! v for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
) C9 n3 y* ?: k$ w addr = base + cnt; /* pointer arith! *// q5 \! [4 w' K) R' ~/ s
val = *addr;
4 T8 j* V& u: n/ }2 E) [+ \, p1 G *addr = save[--i];
: m5 k6 F) G! Z7 l- c2 i( T9 Q if (val != ~cnt) {
* {* ]* o9 L' G r2 u% P* m size = cnt * sizeof (long);
+ L$ ^/ a, H* I! \ /* Restore the original data before leaving the function.4 I( R( X& a ^5 ?- X, P
*/* O% F2 j; V7 t; g1 N0 g6 Y
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
7 Q) b5 _7 v( U. C/ J& H addr = base + cnt;' g4 O- n& }+ U8 d8 F' Z
*addr = save[--i];
9 g* [% ^9 y- W/ S% n7 z, t) Q. k8 r }, \ K# H0 X: @0 I5 m' y% P5 K6 b) l) L
return (size);
7 R0 _' [% E% A1 R- ^& f- v }
6 E/ o ^+ q7 R% _' _+ k/ m }
) G; y! ~3 l3 y* Q8 P/ T; x3 e6 S j. P) {
return (maxsize);3 J K4 t8 E! C+ M: I* \& D
}$ q0 I( V+ n7 U0 T0 T" }$ ]9 m
int dram_init(void)
$ o. V# Y, d y0 P{( K! O e" [- Q$ W4 `8 ^6 n, g! l5 l
/* dram_init must store complete ramsize in gd->ram_size */
6 D" z. k# Q$ J% @ gd->ram_size = get_ram_size(
2 z3 x7 K3 b6 \: G: y0 w/ O- \8 Q/ T (void *)CONFIG_SYS_SDRAM_BASE,( b2 C0 @2 I# m! s3 c
CONFIG_MAX_RAM_BANK_SIZE);
7 Y6 |- }8 T1 O% J. i' x return 0;
1 |: M9 Y8 F! |+ e A: A7 W}) U; ^. u/ |3 F4 T+ l. q; [
3 a% r% @0 |$ t2 o
4 V$ H1 r+ i* D" O. ^+ T9 P) W0 {# ]) y
' U& j3 d! t# h2 f& z, H. v& H8 ~8 [& B, {2 ]! f1 g: {
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!0 @+ n9 ~/ b1 P$ t8 q/ J, j
8 E/ q- y: e$ a1 h. C
$ \2 c/ L& e) o. v6 n7 ]6 ^" m6 j. T2 p# u
|
|