|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:4 `* C% z& `$ D9 V3 ^2 \6 X7 w/ h
/*
# w3 U/ [) v( ^: ^, K4 ^* Check memory range for valid RAM. A simple memory test determines7 y! ?. {; f K. S$ H
* the actually available RAM size between addresses `base' and1 A8 ^) c9 v1 B
* `base + maxsize'.
! N' \) K7 y. X# C*/2 g9 I$ g8 x% _
long get_ram_size(long *base, long maxsize)4 E& y8 E! S+ c. q& v+ |
{
$ ~. Y+ {$ x8 s0 e2 \7 A8 R* m volatile long *addr;
( u9 F7 p+ [/ h long save[32];6 U# h% x( `, c4 L
long cnt;2 L: L V3 N/ }' Y& g# y$ [. J4 |1 G
long val;
# Q# k$ c+ e8 ^/ ~* q) { long size;
! ]$ C6 D; g) m: s int i = 0;
+ X. ~# F6 X0 y5 N3 [
9 `+ J4 V+ v; C" F for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {+ b9 {$ L" F6 `# ]6 l9 j7 u
addr = base + cnt; /* pointer arith! */. Z4 m6 L7 i) K" h. V
sync ();; ~; Z. \2 R- [9 d0 Y+ V8 W1 `
save[i++] = *addr;1 I2 L1 f) O1 s6 ^. {
sync ();! |6 {4 ~5 ^4 F
*addr = ~cnt;
u: k! {. F. Q% i; g }
" g7 S( T' R+ o! ^' m# G" M" @% l) d i: j
addr = base;5 a; S- d% _5 p
sync ();
' O5 b* l4 c1 T1 ] h5 e save = *addr;
. Z( _' o( s- j* b2 b/ A sync (); Z4 T9 ?: i/ N
*addr = 0;
2 C) ] {% b- h* y
8 b5 G- C$ I& z7 X sync ();
8 C; v$ i* j* V5 {+ w O7 m if ((val = *addr) != 0) {
! r$ D" F4 u- r& C4 C8 G$ T5 i( P /* Restore the original data before leaving the function.
4 K# V$ c: j0 c! Y; n6 H; \! f */0 k' `# C: V! c2 E% L) y/ ~
sync ();
% _) a& m9 V: e *addr = save;
5 Y n; u; _2 ^ for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {( L- b, E4 ?$ `5 ?7 P$ r
addr = base + cnt;
4 C8 n/ \8 c/ O4 v sync ();; k* p+ M0 h( b
*addr = save[--i];
8 T. ]' U" |5 l }% a0 j" y$ ^# S' z9 U# l) ^7 ]
return (0);/ Q& D4 m- _4 }( ?# Q9 t
} D$ ?' D) f+ m& v
+ N8 }! y2 i Y
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) { i% d: c, U. h# L1 D, K( X
addr = base + cnt; /* pointer arith! */! i& _, \! `2 u
val = *addr;
9 Q0 i& W% _' y *addr = save[--i];
! m5 \# _! y/ H: K& n if (val != ~cnt) {
# p# H' D: W# z. S9 h size = cnt * sizeof (long);
5 M. x" P" P8 @" K1 C2 Z2 p5 c2 X /* Restore the original data before leaving the function.
# ^. i9 K3 S) ?6 R/ k */
0 i5 i5 E( m" J v! p/ v' X1 C for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {/ c) t- ~. f4 l. u
addr = base + cnt;( e: j* |9 r; b" v9 s% m7 e
*addr = save[--i];
! X/ u% |' x) I }" H: T: D9 _5 m1 l8 E
return (size);
& B4 e5 I# G" p; m% v, w }5 {5 f2 E) E0 t, g1 m, U/ ^7 }
}
5 h6 c" } p8 I4 T/ v; F0 c b
' Q7 o. N. Y" x return (maxsize);% T* B: x5 z3 a6 c
}" e0 ?# X1 w4 a: a! s3 I* v' z2 c
int dram_init(void)
/ h# Q% [. h. P{
0 t4 G+ A* ~6 _( ] /* dram_init must store complete ramsize in gd->ram_size */+ ^$ }4 C, N% z2 f& J, ^
gd->ram_size = get_ram_size(
. u2 d( X5 {: t1 v (void *)CONFIG_SYS_SDRAM_BASE,
: c {& c# W1 P( Z' [, v+ _7 L CONFIG_MAX_RAM_BANK_SIZE);
+ M/ {( o9 h, u2 ?7 T return 0;# i5 _: m# W' B# h( ]
}
; _3 @5 l: y" A( F4 t* h
3 Q7 ~# b: V( E" k. S
. U, b% l( B1 o" [! J7 f5 B* b- T6 b% J( Y( [/ A3 P
4 u/ ^1 X) b6 J7 T9 V* i) Q( y
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
" t4 K0 M. a/ F. [, p7 M) T) [2 e' v/ O* Q3 R3 N$ B* V
" s0 U. E @0 S. \3 P0 T8 g6 Z) Z4 y
|
|