|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:' D5 l+ Z6 U/ @ Y7 _+ l
/*
# S8 [" s" P4 A6 L* L, h8 U* Check memory range for valid RAM. A simple memory test determines9 ?0 U& H" W! \ u8 [: c
* the actually available RAM size between addresses `base' and) |% [5 W+ ]7 [& t; O
* `base + maxsize'.6 P9 y& N0 _& n% l+ J
*// b5 c& S5 X: X; c
long get_ram_size(long *base, long maxsize)$ ]% I& {- @) g/ g$ [
{$ Y$ I3 ^) x6 v4 Z& Q
volatile long *addr;! m0 t! G( P" b1 j7 j3 S
long save[32];- X/ S4 E# {4 g4 z9 X5 G
long cnt;
6 O# |/ [0 y- j8 p long val;
1 q, b1 S' W* U7 v long size;
: M5 ?! l/ ~3 i8 T: C# U int i = 0;3 _6 E/ o. n; V* R) V, u7 n
& i' j' H, E& e7 n) L2 E for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {; U: _! ~* a. Y! g8 p5 Z
addr = base + cnt; /* pointer arith! *// u _- K. M3 P1 D% o0 m- a
sync ();1 ]: j( E# ~6 i9 B1 g% S
save[i++] = *addr;
) q8 d1 O! W i) o( y0 S: t6 D1 y sync ();
% q$ m8 Z1 n0 X5 \& x *addr = ~cnt;
; T1 S9 I3 w( k2 d. s/ w }
" i& }) m: `7 X3 ~+ `
+ J) w9 x" w6 T' }& o: Q$ h addr = base;5 c1 R2 P$ O4 o) s5 R5 U1 j
sync ();
% T& @' X) {% G8 v9 i5 E& {5 q save = *addr;7 o8 R" j: [% s7 q" o6 w
sync ();
5 k* T% {, J' `: @7 l+ ^ *addr = 0;$ v. A7 @7 r% |* y5 b- V- v7 L9 F
/ W5 J: G+ t5 n0 E% q. Y, c
sync ();% a: |. J4 l- x% [9 b: V# B) I- g7 C
if ((val = *addr) != 0) {! Q5 I+ {* R) z' {3 k
/* Restore the original data before leaving the function.
1 \0 H) b! ^$ D( a6 S3 m */; S+ d/ G7 |" U! l
sync ();. _& C% f& i9 {" E2 g6 K t
*addr = save;
* y6 y+ R# L5 \0 Y for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
. H9 j/ q+ s& C0 ^5 O! V/ C addr = base + cnt;
1 [0 R8 R8 u+ g! i) Z* ]( k sync ();9 u0 m3 u, D7 H3 H3 V0 F
*addr = save[--i];4 y2 r. h2 P B m( ]" N
}
2 |3 M) [7 {* x; Z return (0);# n& |' j8 a7 r7 V
}) \$ o- S, }) O' _9 H5 a
! r3 W [, G. @
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
; o1 q0 s+ U& _. | addr = base + cnt; /* pointer arith! */
- ?& i7 [% u6 j$ ~$ {8 E, g val = *addr;9 P" I& c& [7 G+ ?: H8 K
*addr = save[--i];
/ N) s) H' t6 O3 a if (val != ~cnt) {
h( [" Q. O6 y* q( [8 v size = cnt * sizeof (long);2 _( P# Z$ R; ^, o
/* Restore the original data before leaving the function.
3 Z4 @5 l# i+ ~4 _- d/ {# D& F */
8 {5 L. b9 V5 Z E$ Q for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
/ ^0 v% n, [( r addr = base + cnt;
+ t# O' N0 F1 U+ i *addr = save[--i];' J. T. O7 P9 i0 e
}5 u& _* D* w6 n/ N9 g. c
return (size); N4 m& R) S& o
}
1 j8 f. ?8 a; T. U3 `, s! U }' \. O0 E2 Q# i4 e; Y% l' Q
- ]; g4 Z$ H, Y" P* X return (maxsize);
' ]! q% J# L" U, N- W9 H}
5 Q) z- {* S; w2 Fint dram_init(void)7 |8 D# L U; |5 }( _; w! K
{
( y- |1 ]$ A% A* `6 }+ V, l" D /* dram_init must store complete ramsize in gd->ram_size */; y: s* A# S" P+ _$ M2 x7 u
gd->ram_size = get_ram_size(9 y& B8 O9 s' j7 V0 f" ^$ W8 w
(void *)CONFIG_SYS_SDRAM_BASE,
! x( a+ {! f# Y: \) X/ `* e) E CONFIG_MAX_RAM_BANK_SIZE);" u6 S9 o, \5 b' X5 P. J
return 0;+ r/ N7 S3 v$ a! v- n2 M, V9 I
}
. `/ f* C! L$ v% ]. s1 f% N/ f5 g7 C$ V" ?6 e- N) z
2 k1 v4 [; n; R) `* S0 k' q' V1 i9 X
' I A8 }- p4 UFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!' F. @8 i1 q- L% ], x+ ]# @
; i9 X* l+ J, ]
j8 L+ U0 w; d+ E$ H4 ~
/ u. L T* F) s9 B6 h3 i. V3 p! L |
|