|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:! Y4 i. F$ s$ f6 f8 M5 f' j* |
/*
2 o% @. P5 [; C; l5 U8 N+ A! B* Check memory range for valid RAM. A simple memory test determines
, u- p7 x* U {8 _' y6 v U* the actually available RAM size between addresses `base' and
: z# M0 K8 c, K a* {% u* `base + maxsize'.
% s8 t; [" o: m/ c4 v*/
; ~% M! u0 i* v; i0 f2 s! l3 ~" `7 @long get_ram_size(long *base, long maxsize)! F8 e& t* E+ J1 y4 N, H
{
2 i! T( X! V) T' U0 V, I volatile long *addr;
0 A3 ~. |( i6 h, k. N long save[32];4 z$ Q, H E8 I9 T# V. K; `
long cnt;$ z0 G5 H0 L) E0 ?+ N
long val;
$ ^& {, f+ ?8 G* |$ C5 C long size;
% C1 [2 J r& j# i+ k int i = 0;
6 `* p, j* P; E2 b! ], p7 y' `$ Q! K5 u; Z# Q1 s
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {! k! A) f" K2 u3 w& h' Y
addr = base + cnt; /* pointer arith! */# c$ W! R3 [. h- h- z: E; j7 d
sync ();
% |2 ^! Y" p7 v# K4 H6 A save[i++] = *addr;; q8 B" K; F$ {
sync ();8 C( P2 V% E% z6 R( h" ~- b5 h% @+ {
*addr = ~cnt;
6 t% n% Z d a% g* G }, X4 p3 W/ e1 ^3 @2 F& l+ E; [
! G1 E: l, y# U addr = base;
# \4 |& q Z- `* V# ?9 ^6 M, X( P sync ();
0 ^! H, O0 c" V/ U5 e) k* K' s6 G; g5 o save = *addr;
8 l: u0 z7 k6 E3 R t- S2 G2 y sync ();$ |% ?% g9 z$ ~! U1 B) P' s
*addr = 0;( ~1 z# m' o* k1 n, k
5 S: R% Y1 F- J4 @- ~1 U, P sync ();
7 {2 N6 v/ X& ^' S if ((val = *addr) != 0) {
8 G) r5 ` m% T$ l/ a Z /* Restore the original data before leaving the function.! z0 c) ]8 n2 B* o0 g! H/ a
*/ Y: Q7 u. B- N6 }& ^( ~ x$ w
sync ();% M7 v3 @, y( `
*addr = save; z5 j: l5 V2 P) a
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
0 w A" e% v# p1 y7 e9 t) P addr = base + cnt;+ j# E$ C. n' A5 g4 K' P9 x7 K
sync ();
6 d4 n3 \5 S0 ]- G- S *addr = save[--i];8 k( }8 m+ v: W f) l8 a: i# i1 A. E
}* u n- [7 Z3 G+ }
return (0);& p, l" p& _; ]& ~& u* m
}( }9 R/ X. I7 O( \* n
7 i( N; l9 E4 v
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
- D2 Y N) A5 e6 `& s+ g* W4 O addr = base + cnt; /* pointer arith! */
/ C/ e! B: \8 G val = *addr;
6 q+ [1 k( }& f *addr = save[--i];
% I5 H6 ?7 }# |) U if (val != ~cnt) {8 h8 }: O0 n4 Q" f, {2 C
size = cnt * sizeof (long);
( e9 ~1 g9 g% Z2 |- ?" V$ @/ X3 c /* Restore the original data before leaving the function.
6 a! I }2 ^. d9 E */6 F5 {/ B: D7 z; c. G! ]2 N: r$ d4 D
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {& F0 _' X5 v: M) X' Z6 y: c
addr = base + cnt;/ M Z: a3 `6 p2 M4 I
*addr = save[--i];
6 V9 G# f3 D4 w% z9 S0 _+ ?% b) Q, B }" p. w; _7 F" ]& w
return (size);8 b a+ q7 A1 _; k; F1 q
}+ a- o- [. \7 ?* ~) h4 F
}+ v$ M* x* n J4 @9 w J
' B( {$ k3 I% v+ J: C
return (maxsize);
# t; c) h3 I6 a: \: T}9 O+ x% Z) J3 g8 ~ F
int dram_init(void)
' y' {3 `/ J5 {3 T: }{" O) K) t# i1 R% g( u9 S% O7 F
/* dram_init must store complete ramsize in gd->ram_size */
$ V$ \, E. `, v8 D gd->ram_size = get_ram_size(6 f$ t) v+ V' g% C& {& M
(void *)CONFIG_SYS_SDRAM_BASE,
; x2 |; ^# J" E: ?( ~) D! Z7 L CONFIG_MAX_RAM_BANK_SIZE);
, @" b& q; A) A' l3 s0 l$ j3 m9 ]5 ? return 0;6 g0 F( e- J6 |& A1 `4 ?; R
}
, Z1 T3 ~; Z4 M& M7 S0 _ Y! P1 F. v6 L4 B$ [* [1 S( }2 O7 q+ t( G
1 {* \: c3 q" `
; M' x& h$ q3 ?' O- G% E& [# K' w8 i4 p
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!7 }0 O9 D3 h$ {
; j, j- u1 H" h" r7 f: S7 h
, J* A0 d5 c$ \4 V
( a% w" Y& @! Y; |% ? |
|