|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
! D, A9 o3 W7 a5 S9 }# n/*8 {2 r. \& k0 u) k
* Check memory range for valid RAM. A simple memory test determines
- P" c6 }+ K+ D3 n# y! \: y* the actually available RAM size between addresses `base' and8 n$ y* Z# Y' F. v3 J
* `base + maxsize'.( |$ d/ n T) v$ Z& F
*/) D+ W' U) J3 d z" l
long get_ram_size(long *base, long maxsize)1 |9 D9 Y% T2 C$ F- |% C/ p
{
7 _ f! X) {& {9 n5 W0 f# }! j volatile long *addr;
0 A( J6 C/ D% f% ^' k long save[32];
5 X/ E) q' U8 I9 S b3 \2 L long cnt;0 b5 w8 n3 @- w& [ @& \0 p
long val;
& t. n' W' c- a0 r0 g( W$ `5 f5 _ long size;
. p8 j/ _: r5 U a int i = 0;
( m7 p6 J% T" \- B* D7 i% ], x- c2 ^( |4 b' _. F' f$ z1 O
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
- \6 N# s; w; J+ o addr = base + cnt; /* pointer arith! */
- O! f9 F- e) ^/ K& a) t; j: z& T# e( n0 z sync ();' t& } ^. E& E% k
save[i++] = *addr;
; t* i: p9 [# f" S7 H1 @, N- n7 ?9 a sync ();
1 l( T9 r! j* e, V *addr = ~cnt;$ c% P0 P! m2 Q1 w6 @/ B
}
2 o! r4 S1 V t1 @: ~& Y/ E) V% o+ U: f- v% M' l+ o
addr = base;
' v1 v. b* T1 F2 ~9 @* Y sync ();# H- ^* W, ?) Y
save = *addr;
% P& l2 T7 c/ n sync ();0 T# ?! ^& m" Y R
*addr = 0;
% b+ g" Y% t. B3 [* s+ P C- f! |% j6 ^& X* `8 ]; V
sync ();: e0 N W. W, ?8 c- h
if ((val = *addr) != 0) {
7 a) m3 n* b, j! h /* Restore the original data before leaving the function.- q5 ~5 `3 N- D' y: C$ T, ]
*/
; S- p2 l: ]; _) J& W sync ();1 n$ Q, s2 \" P7 w: k1 P5 E6 f
*addr = save;# y" e8 H% Q* n8 P
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {/ E7 C+ l# l: a7 Y# D1 c
addr = base + cnt;9 k7 Z2 a1 G" x) U8 x! Y
sync ();2 z& p) m* U# V/ C9 _2 u
*addr = save[--i];& A0 A+ W& R" j4 ]
}
. Z7 z- Y Z! E return (0);& s, q; P- ?0 X
}1 @2 D" ~; T& @: W* E5 H
! V$ R( A5 C7 I7 [8 Y* f
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {, R" L# }( }& L$ z9 D8 n0 n
addr = base + cnt; /* pointer arith! */- M3 ` j# p T& M" a8 {
val = *addr;
, v- |3 g8 y& R" [7 E *addr = save[--i];4 t# H s4 C( d4 L2 b
if (val != ~cnt) {
: O2 h: q$ I4 r( E5 ~+ o% K% y# \4 | size = cnt * sizeof (long);0 s3 t2 w2 x. t) P/ G/ y
/* Restore the original data before leaving the function.5 _* X3 u4 g, p7 c* w
*/3 I/ }+ C5 U( A* S, }* X& U# o9 c
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {, U; ?1 i2 X n* F% W2 w
addr = base + cnt;
8 e1 P0 F0 U' ?, P *addr = save[--i];
/ L6 s T' Q" k" A! c) `$ u( s! W: o }
4 F R; v( x- r- r: x/ \) O return (size);( K4 y1 S+ h0 ?& _6 G: J) }) b& A
}
% A. z \- D8 p/ j }8 z) N `8 I6 Q
# s; q, B8 ]. z0 w4 k; ?% ?
return (maxsize);! a, o" {7 l7 f7 @3 X" j
}% l* a) j, h$ f) w2 Z
int dram_init(void) d% t: n0 u7 e# l( R9 i
{0 Q; J8 G; [% d/ C; V
/* dram_init must store complete ramsize in gd->ram_size */
' @9 ^. Q O* X b gd->ram_size = get_ram_size(, z2 J0 J; t8 @( A( I
(void *)CONFIG_SYS_SDRAM_BASE,( m; c. L3 Z) i1 j" l# l# Q N4 C
CONFIG_MAX_RAM_BANK_SIZE);5 S0 v( `- Q6 c: ~4 p/ s
return 0;! c n, v |6 D' G9 S/ D" t. o
}
+ X! J1 w9 ~3 D- T4 E/ K- J* Q% [! N- L& L, x! w
) I4 W1 V, c" h; Y0 @5 a4 N" [
0 i( M6 `2 ?7 i! H7 {
5 e# M5 E. w* q9 r: ]. rFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
3 n5 D- ]+ h+ _. b9 |+ O
G5 ]$ `: C& F7 i# s% _2 ]3 s2 V* a! Q- n$ R3 o. x, |4 b$ X
% U3 Q T1 m9 A8 {# x, Y3 z
|
|