|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:- ] ~$ y* a8 e3 A
/*
9 E p' |+ M2 v* Check memory range for valid RAM. A simple memory test determines
% N( c* k, z5 x$ L5 |" ^1 f* the actually available RAM size between addresses `base' and
5 n) q- \/ l+ B7 g9 ]* `base + maxsize'." O- h2 l7 J" P9 o
*/
% k0 F6 O6 n3 Z8 n+ T' t' ^& Zlong get_ram_size(long *base, long maxsize)! Z. v4 h1 K# C) S6 \; E! j
{2 o* W! p, B2 N2 H
volatile long *addr;
1 \( s5 U- w) J8 R$ d0 h4 S long save[32];
h: V6 ?) f$ e; y' j. N long cnt;' q7 Q( r( [9 p+ @& |4 |" C2 N& s6 ^6 e
long val;
0 x0 w/ P% b4 u( j long size;
2 o, B: g3 k \: L) u int i = 0;
* F( f8 U" O: {
' |! M; _6 Q2 C for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
; r' U/ A+ P/ d3 L1 q addr = base + cnt; /* pointer arith! */' ^* Z* O4 N% W
sync ();
5 j1 @! c' U1 {# e, `: x save[i++] = *addr;1 j! e( l9 H% P8 y/ i
sync ();
2 s- J* v n! P" D6 p *addr = ~cnt;
9 e6 j% d: t/ c }6 Q" V9 d: ~% _# X I& p
+ L3 W5 p. C0 I) ?' F0 j addr = base;/ o, j& l L8 i( B( D( j
sync ();& t) C/ I) o& r) M2 z$ T0 J3 h
save = *addr;
/ C# |! ]% G5 u% b: Q' q sync ();
. s, y% F/ s# a5 ?' C *addr = 0;
: u$ ?% K0 `( t9 j* n5 Q2 Q, V' A" @' h' ` l
sync ();9 q$ _+ `3 R; w1 a' _' \
if ((val = *addr) != 0) {
( m4 x9 u& n. v0 ?9 ?1 s- `( a /* Restore the original data before leaving the function.! h: b& Z. v4 n, j! p
*/
$ n0 l1 Q6 ^" [$ O sync ();
* N; Z/ v l- _) K- p7 N *addr = save;
7 o1 H& Y' b. x8 F% l2 Z$ w for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
* b9 [6 ~5 F! D7 s addr = base + cnt;; C- {) R7 z# Y2 c( F: s
sync ();
9 p# q0 c5 [4 }9 x1 g" I0 H4 G. b *addr = save[--i];& b7 d' O( Z5 W" q0 \0 y: L
}
. Q: s; n, @! }2 q return (0);! R& H1 g; }, C2 q1 J
}
# {6 M* N t. G& ~) Q
4 z1 h' Q. q% R, ` for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {7 _3 u: Z0 p: Y$ H! z
addr = base + cnt; /* pointer arith! */
8 K1 L+ j/ m8 A7 B5 ]; v val = *addr;* q, T5 a6 v( M% r+ ~
*addr = save[--i];' g+ B* Y$ s4 b8 a" j, z) {
if (val != ~cnt) {
0 n+ q* f/ A8 d! O size = cnt * sizeof (long);
. U# u0 g1 E5 G8 R E4 w /* Restore the original data before leaving the function.
6 u# I+ D9 z6 S3 Y j" e! u8 ?" V */
! |5 `5 N, y, m$ d: b for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
8 v4 a7 i5 H4 l addr = base + cnt;% U/ \% y* [* N5 |3 M0 {. X
*addr = save[--i];
6 v; e: N# G# |/ L }8 G5 z0 j4 ]) X& A, t! |1 w
return (size);
4 \$ v1 D3 ^/ l }
. [' X! C' C; g7 N0 l: W y } e7 d1 y# Q5 C) [* t; O4 l
% R- F. b( ]' W) y4 _' ^1 ^% G& y- K return (maxsize);* h2 x9 c$ b! f% L+ @
}
3 I" w; v+ y+ W7 L1 A# L; Sint dram_init(void)1 K( Q+ s) {+ t6 Y( U( N
{
- |8 W! J1 a- q) E- K4 P /* dram_init must store complete ramsize in gd->ram_size */: B2 s# h/ E. d4 b" N1 q
gd->ram_size = get_ram_size(
. s1 [5 z# T+ c1 [0 a% U* x (void *)CONFIG_SYS_SDRAM_BASE,
* B* `, O( [, n- X/ h CONFIG_MAX_RAM_BANK_SIZE);, d- P9 U$ d3 c& P, i9 N" ]
return 0;$ g5 t6 a9 J& \2 M& g1 ~5 @# d3 U( u5 ^, H
}
" L& b) f+ r' \- ~5 y! |( o# P7 m% z0 s7 c
" U# U5 v8 v- w' n: I: i9 s
+ I f- K2 C! V0 B5 s+ u
: i; Z6 d" u* i+ _5 LFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!: g3 `4 d, n; e4 N; j) y
2 |8 Y) M; P7 x9 l7 k# V! V
. L: C" l j. t
2 j/ n7 R! Y4 h2 b1 f) L |
|