|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:5 X9 G) `7 m& R- Y
/*3 D4 |4 X8 \3 z# O l
* Check memory range for valid RAM. A simple memory test determines
; w% ]) p2 Y( u! }" b3 u, {! J3 `* the actually available RAM size between addresses `base' and
, D1 w# W" x8 u: z* `base + maxsize'.
! b9 x" Q" m* n! K7 y*/
' w' y- D3 |+ p" a3 jlong get_ram_size(long *base, long maxsize)6 _) | N, \; w" r% R7 e2 P5 u
{
; b! n; m# [ z9 g! G* L9 q volatile long *addr;
+ E/ P. J* \$ a7 v L! h long save[32];
" m: f( S. b4 H long cnt;
" w4 \ d# O& U* p3 J' A% a( u long val;
. j% V; y' b, @) R+ t- x/ V long size;
C" G* e: H3 m) A int i = 0; D5 [2 Z/ ^9 h2 {; ]; m
1 _ Q9 ?) t- o. V W
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
* Y' P. A. t1 F8 P1 z$ h4 ~ addr = base + cnt; /* pointer arith! */
1 M; l5 J( R7 E& o, t0 r sync ();/ ~' [1 K- k+ k2 e* A. B4 G6 m
save[i++] = *addr; p9 Q- w1 k: o5 J' _
sync ();
& v: C8 p$ b& I6 F8 u *addr = ~cnt;+ g H( e! L& p" Z; f9 c2 R, K
} c; i5 T$ @7 I# |' ]6 D
: ?( [7 @6 A# g& @$ t, \! u6 j N
addr = base;( `. c1 \. s0 u$ {# V; z B. y9 r
sync ();8 m" k$ Q$ G. F
save = *addr;
1 X: W4 N0 f/ f. k* O: ]( ]9 ] sync ();
5 \* H6 c, E# O0 Y: z *addr = 0;
/ u( c9 J9 g7 Z K( ?, J- p
* t& c! J( V [ sync ();
( ]( v+ n( ^4 O if ((val = *addr) != 0) {6 i% P1 l/ D5 i5 ]- E2 t/ |& z
/* Restore the original data before leaving the function.6 ?& N" X, ^" E- T4 H2 Q; j) {! C
*/
A: M3 |! L9 ?6 g0 y7 C" [0 Q W sync ();9 d4 |/ u; U" _& \- U2 Y, |( ]$ U
*addr = save;
7 [! H9 [" z7 Z I for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {& z/ v. t( G( `/ W+ J# F/ o$ D
addr = base + cnt;2 G9 R( u" p1 M
sync ();
2 W: s0 G o& N+ e) L0 B *addr = save[--i];
) Z5 u1 o8 b1 I3 q& } h }
' I( J! G3 X+ e6 H+ p! N, m return (0);3 K3 M8 o; K. `7 Q0 ^: i5 g
}
% f( D# G7 p( K9 @8 K8 W1 y, n8 f% \
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+ ]; m# E. R" Q! \, M# t# y addr = base + cnt; /* pointer arith! */
' t' w5 T/ S5 ^9 u6 w% V val = *addr;
* v% x$ N) x9 F: g- J *addr = save[--i];* L K6 g; h+ q0 d3 r+ Y
if (val != ~cnt) {
& V2 ]. T; d1 a size = cnt * sizeof (long);
7 B; P! Y4 @1 I* I# \; J) t /* Restore the original data before leaving the function.; o& T8 O2 S' u( M! J
*/
" x2 R4 `* h4 s$ d1 M" r" J for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {+ c' h4 R! l0 |* M7 W% F2 b9 y
addr = base + cnt;
/ i- d9 H9 S6 Z5 R. k3 H *addr = save[--i];" u0 l: s% u. o" O4 M8 {; G
}
/ M7 u3 Z4 B/ ~9 b0 ~6 r return (size);
' p8 b- j. }; A j }
8 u2 M ~' u0 M2 d5 T }
# a, W6 h6 `# T( A- E0 b+ g5 {5 W
return (maxsize);
5 M# O* j* ^, U' i. F* A! m5 a}
4 f- U3 D. N. s8 dint dram_init(void)
8 }; w9 ~+ i3 J# ^% F9 B( d{$ s; b9 b) L2 e; `4 T9 ^
/* dram_init must store complete ramsize in gd->ram_size */
/ b# U; e5 L3 a gd->ram_size = get_ram_size(5 I4 ]' U1 l' V! `
(void *)CONFIG_SYS_SDRAM_BASE,9 E" |- C W: ?! i
CONFIG_MAX_RAM_BANK_SIZE);
" K* ~- g, O- p return 0;
+ x% I9 _: ~6 R1 }4 ]! s}! V' @7 o0 E) I/ {% ?
8 S5 X4 `) c: I2 U" d* j; y0 a% {9 Y/ K D9 X2 @
. E/ z W: S5 E* M+ e% m. [: ]
: z0 D( J0 H& ?" K* I8 m% A, m ^
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!( l; O+ h. V( U c# s9 q
- f, F! F# G. D( D4 R/ Y3 R6 T$ }' ?' j; y5 i* b; R
6 W8 {$ u; c" G2 J2 C
|
|