|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
) O; `/ L+ d% O7 P! R! m& o& l/*9 L: l" b+ {6 ~* D _
* Check memory range for valid RAM. A simple memory test determines# g! K+ I$ s- l0 L3 p M6 g
* the actually available RAM size between addresses `base' and# y/ r) G6 M- J' g- e9 N6 ~
* `base + maxsize'.
$ a g9 k& ]! x2 Y1 H*/# }. c" E% W( Z7 M2 ?4 [4 @* s0 Q
long get_ram_size(long *base, long maxsize)
^8 R1 H; y8 P{
, b/ y) T2 _1 `& W" z volatile long *addr;
b; m3 I$ V( {+ Z$ h. s- a long save[32];" m2 m$ f o- n3 B; v# u. v6 t
long cnt;5 f; w3 a" V0 J& y
long val;/ c" O6 H+ J7 |; C
long size;
$ N+ W- u0 C7 g% K) Y2 |6 V int i = 0; c8 @0 _9 E) G. l
4 h8 w" X J1 g8 i
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
" _% @. a& m: Q9 V/ J8 u$ j, c: t4 } addr = base + cnt; /* pointer arith! */
0 c+ d$ N8 r8 ` sync ();8 g; w9 J( F- v8 D5 S
save[i++] = *addr;% `; m0 b: {4 Q# E. d* ]
sync ();
0 S( E3 h$ @# w5 n *addr = ~cnt;. d! a- @# ~- n3 x/ @0 u
}
6 ^0 V! o6 X% O5 `% F8 @& Y
7 W+ m$ S8 n% [ addr = base;7 T! ?% @. K6 \: T% K+ q
sync ();% q# K8 I3 E5 l; S1 H1 O7 E1 S- v
save = *addr;
3 P' ^( r Y E) F sync ();, i3 g+ F" ~, n3 l* z
*addr = 0;
* q( v! H; } \5 x
+ U3 J7 B. q, f$ @: @, C9 c1 r sync ();- C* c* v. E2 k M9 @
if ((val = *addr) != 0) {
% d3 E; d/ [/ `2 p, X1 y1 s) u /* Restore the original data before leaving the function.! @+ V* F$ }* w4 a) d4 ?* ^
*/
) c" m& N2 p1 T0 F7 _+ j) o2 |9 i sync ();
; n2 E. h9 N3 M, k ]( V *addr = save;; M: f2 v Y9 T
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
) [- T0 L6 V$ V B d addr = base + cnt;3 F' M% Y; ^$ ?& r0 @* T
sync ();) u7 l. F5 d# r) y/ F
*addr = save[--i];
" w9 w- U3 |% ~2 x4 \3 K }
* v* t2 c7 d+ ]9 V# { return (0);! e0 q( h" Q3 n+ T) A: O- x
} |6 R# X4 F$ Q/ ]6 [
1 _, r1 h/ [7 q, t' ^
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {" n# I: `, x& Z$ H9 V+ a2 Y+ Y
addr = base + cnt; /* pointer arith! */3 ~6 y( M" P' ` W7 h8 l% T
val = *addr;' T; _* Y k0 n
*addr = save[--i];5 y s6 L$ Q3 ?" u0 J
if (val != ~cnt) {
+ |8 E0 ^& v3 Z; e2 L5 | size = cnt * sizeof (long);8 }+ l3 r; h- Y' N6 e" |
/* Restore the original data before leaving the function.( y$ A% s9 L, R! i- W
*/# P1 N' a; y( j, \$ U# a, X
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
. U7 h7 b( A' u) g1 A addr = base + cnt;4 k+ Z+ W% O1 _/ @ O$ p
*addr = save[--i];
* }# {: H. v0 J0 t7 r# Z* s# G/ M }- X0 V {2 A! i
return (size); ~0 U$ D+ _9 w+ e5 t- Q3 w
}( _/ J( k- C' S) @% e
}0 I$ A0 f; ^+ u7 M) @; f' r9 p4 t
( ]% m6 I( Z8 n$ [/ B8 U z$ E
return (maxsize);
+ z; e: ^2 G! L$ O* }- g}
Z0 C; }1 l+ a" B" Pint dram_init(void)2 x3 j7 X' P I
{
4 d9 L; S& b- P4 H /* dram_init must store complete ramsize in gd->ram_size */' o* m7 E( [7 o8 w A! ~4 I; B
gd->ram_size = get_ram_size(
2 {" ]/ _% N+ Q( }- { (void *)CONFIG_SYS_SDRAM_BASE,' Z+ b: a7 Y' I1 `8 k
CONFIG_MAX_RAM_BANK_SIZE);6 T2 P5 J: I$ o* k
return 0;4 O( \- V; J- b
}% A. f: }1 J! ]5 q
" t8 {3 \+ G1 S3 z3 c
: P, z, j3 w' B" u3 G5 ]+ y, s) X$ ?1 N
; [* ` K" R6 M5 R
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
) W5 g! ~7 E: z1 o
% {! E4 Z' h4 w4 w, ^1 ?7 v j- k
6 e! M$ Y) ]! s6 }+ C9 ?! @9 {3 I3 w) @
|
|