|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
( g' |; d$ |/ {/*- {, Q) E; b7 w
* Check memory range for valid RAM. A simple memory test determines
1 a! Z" h1 r5 P9 f# \1 o* the actually available RAM size between addresses `base' and7 R9 E z( J* m3 q, |
* `base + maxsize'.: H( f# {! Y4 b! V2 E% T
*/ X% M% P3 Z' A5 I) E& ]. v% r( ~! Q) I0 c
long get_ram_size(long *base, long maxsize)" x. a1 k! P: R" Z9 l# L
{" X5 W: b6 A/ }9 q# o j4 ]
volatile long *addr;
$ Z+ \ _* E1 F% F2 |- T long save[32];
' z$ ^4 ?3 g3 U2 s3 Q( f long cnt;) E/ L0 j. c+ m7 u
long val;
$ S1 S' }& w5 j& }6 e$ Y long size;' I) s; d8 {& a4 j, y
int i = 0; M' s& X4 z9 m
`: i5 k9 j7 h$ f
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {+ r& _' P# B$ Z& E, Z2 x! {
addr = base + cnt; /* pointer arith! */! c" D' c, o5 O6 ~
sync ();3 [5 [+ W4 b' ]" ^8 i! D
save[i++] = *addr;0 ^& J6 k7 z% Y8 g b
sync ();
# C6 f& ~) B! H7 M* J8 b/ N *addr = ~cnt;
; U. l( Z# _* f0 W8 A0 H }
; i6 L+ e, U2 S& X( ~
2 y% ]) h2 E% U addr = base;
0 l' M- ~4 d4 }8 Z sync ();
& y- p/ Y6 }2 p; } save = *addr; ^& N, U* n% x( b
sync ();
9 i! R: Y2 l8 g" W' I2 _, ` *addr = 0;
% |5 t3 {3 n" z; D# ^
- D+ U& \4 U) L& y7 R sync ();% S3 f( w3 y Y# R) k
if ((val = *addr) != 0) {) ]8 b1 O% `- ]6 f7 Q8 I3 `
/* Restore the original data before leaving the function.5 n& E( s$ @! M! a0 b r4 Y9 B
*/+ I& B+ s! ~; }) Q( D
sync ();
1 G+ Y- q& {2 d" {1 B" T, ]: M1 p *addr = save;) b4 Y3 `0 y' `( F G' K& H4 q
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {, X' T2 U1 Y9 c' N; K4 F
addr = base + cnt;# `1 u. c" r- ~4 u
sync ();' u1 ^: _, i5 @4 L' }) ]6 p
*addr = save[--i];- j5 G: L' e* Z5 V
}8 q1 _0 R' X6 A, } K
return (0);$ n! J3 d6 \9 m1 g6 Q( i
}
8 s. D" M4 d8 k [ j' C& i7 U' s9 x$ r2 s
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
* `4 e/ T/ k$ x ]0 J& f$ f( I addr = base + cnt; /* pointer arith! */
5 q& G0 r3 r# X$ X* N val = *addr;% f( j& C4 I" o8 \
*addr = save[--i];, G6 a7 u: q6 c3 g
if (val != ~cnt) {8 }: e: ~- y: E" v1 j/ H" b! d
size = cnt * sizeof (long);& g* U5 a# V1 ]' a, Q, \* J) m$ G
/* Restore the original data before leaving the function.. B( }0 C- q6 k; k* G
*/; w$ G# ?2 L. `# v' F% p" R
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+ |% W$ o4 c* L+ s+ X addr = base + cnt;: u2 g- [* m1 B& Y% j& h# L/ H1 g
*addr = save[--i];6 d% v8 r0 f5 [! `* u
}
3 q5 `/ ?7 z1 u0 a4 v8 A" b return (size);
- k8 M; I: S0 @2 n }- d: `5 M5 W0 c! I. L/ I9 e3 f
}2 [0 y; b& d& A& m7 i
! F3 D0 q, _ { U return (maxsize);6 b6 _, w9 K" `, h- n; p& ^& V
}
- G& c+ D, i d3 Gint dram_init(void)2 V8 @9 ^4 p$ O( a
{/ ]; j# w* f1 k j$ `' H, x
/* dram_init must store complete ramsize in gd->ram_size */& _6 j: [& S1 ~1 r2 Y) R5 q- b
gd->ram_size = get_ram_size(. n* J3 `2 {" [/ v) U
(void *)CONFIG_SYS_SDRAM_BASE, E5 Z! q9 v( o* Z0 [
CONFIG_MAX_RAM_BANK_SIZE);! U9 A" ]9 {6 H3 }3 Q
return 0;
1 M! X) J: P- ]$ x y! {9 v}" J) b, w, g+ E
0 K2 L$ [# L( ~+ T8 v9 x5 Q7 i$ x1 T
* m1 z$ F6 ~" O
, H: D( e5 W S) ?) N6 e) F: FFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
$ ~5 |) j8 y2 F- o- p9 n2 ?
2 f5 }& l# P, F( L5 m4 {5 `3 M9 h; S: R- t9 a. p1 ~7 Q
- O: _ g3 ~( H5 s: |, S" h# W
|
|