|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:% @& ~: D6 P1 ~! G2 g1 A' {
/*
! F' t# p6 ]$ M h0 R* Check memory range for valid RAM. A simple memory test determines
2 S/ W! J$ G/ r. ^! M* {* the actually available RAM size between addresses `base' and
* [+ e6 V9 u4 P) c3 i+ w; i0 F3 h+ ]* `base + maxsize'.
9 U+ l' w% E/ r2 D4 W*/
2 j8 C5 G3 R( @7 p) C9 D. I1 Ylong get_ram_size(long *base, long maxsize)
E: M% P( b" M* F% ^7 L{, A8 ]& z+ V) x# t
volatile long *addr;
! ]+ D$ h9 x6 A$ C7 o long save[32];) D. b5 O9 ^1 _. R+ N. [' e
long cnt;' u7 h/ C& L. p3 F+ n- V
long val;
- k7 g! w2 k1 H& b4 T. V1 u long size;% k. e3 k1 r$ V
int i = 0;: m- b: F# [ q1 C' `. a e; u
! x7 e. Q# T2 v
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {# n) [0 c) |' s
addr = base + cnt; /* pointer arith! */
8 p& ^6 Y- Q9 t( O# Q sync ();
3 f. t6 h8 {9 y save[i++] = *addr;
) f- V' X! a/ P! ] sync ();1 H4 F$ C( j8 g4 S" d
*addr = ~cnt;
7 d$ D/ s/ I, u, o$ t9 p g }
4 a% q' ~# [# e% ?( v$ L! ?" c! M+ G1 b5 h/ L# o
addr = base;+ s1 S% y8 H+ d# @! Y+ O1 C
sync ();: G# k& `, }2 k) n4 j4 i$ ?
save = *addr;
* m6 h# Y0 k* C4 ?8 W sync ();, A) ?) m, I4 D! F* W9 t
*addr = 0;
; u0 x$ @( \# t9 Z: X4 @- R2 j# Y. m- S5 J( u0 K7 n
sync ();- n3 @, J) t1 s! _3 Y, n. _% Y
if ((val = *addr) != 0) {2 B p. F- f" V5 D/ O
/* Restore the original data before leaving the function.: B9 |& R/ u* q8 y
*/ V; A. s4 p8 U1 U! T9 ]
sync ();! i+ r$ f0 `1 G, u
*addr = save;
" m% J6 N, R+ K1 K3 \; | for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
0 ^3 i; O9 d; }2 }0 P4 \, D addr = base + cnt;3 t5 f! }8 A% x9 ~: L
sync ();
( Y# q( g+ s+ C *addr = save[--i];; C4 _* M- N. X0 C3 h. x
}6 ]% F3 X1 j! p+ M; b: ? {
return (0);
2 E" [9 W" t6 p }
. W7 D6 s+ X1 a$ r" |! s% L, E0 v5 { R, q* W) w3 q7 O
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
- n( T2 f8 d5 V9 Q; \ addr = base + cnt; /* pointer arith! */ X3 ~8 |) j2 m# A
val = *addr;. C3 H7 h+ m; K/ N! L0 @2 {
*addr = save[--i];5 j( Z8 ~" b4 [* x5 G' s% Z
if (val != ~cnt) {% i' m" T* m$ f# a4 N
size = cnt * sizeof (long);: Y- [$ g! {% g$ O# P/ a! S
/* Restore the original data before leaving the function.
# O. t& D1 x- G5 A j& J! N */
5 s$ d! }: o1 C! F L for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {( l% j7 ^. m; f2 X2 x4 O7 D
addr = base + cnt;
! t" H3 D/ R" D* J' m. H *addr = save[--i];
3 J4 T8 B+ d! N4 A4 K7 b }# F. [) t8 F, z% l% b% U2 R: q
return (size);
$ `* r5 c- C: u" j( ?& }0 r7 P }
% z2 w3 i K. G/ i }2 u* \/ O: t( w# H4 j0 |
: v. p2 X0 V; S% a7 _ return (maxsize);
. a$ S2 E# `& U1 z2 m2 u0 t}
4 u8 }6 g; v6 S. xint dram_init(void)
) s$ R9 G1 ~& q! u. i' H{
* `, I# a: s9 a9 |8 g9 q; P /* dram_init must store complete ramsize in gd->ram_size */
5 \+ t1 ^1 N3 N5 E0 F5 T gd->ram_size = get_ram_size(
" M" j7 X) A) D/ | (void *)CONFIG_SYS_SDRAM_BASE,
6 |& d, C5 s/ X7 ^6 _+ r CONFIG_MAX_RAM_BANK_SIZE);
0 U; K! e$ r) f' d5 Z return 0;5 ]% s z" g4 y1 U: \ I
}; p0 m. I; e: D a: G
^# b5 f( Q4 F( _8 `* w
7 }5 |% h. Y2 ^' B/ f1 l
: b) p" p5 K; @) G8 }* D; R0 f" c6 x1 @9 |
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
1 g' R! M; }. ~" c7 y% f8 u0 i$ W8 d& o5 C
# k9 {( Z2 V p7 ^+ w, {6 d1 q
$ m( A% t; A+ z4 q/ T+ { |
|