|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:0 S5 e7 e+ E; x
/*
- `6 |2 v. `1 e) E* Check memory range for valid RAM. A simple memory test determines
+ Q" I" h0 b' o9 Y, q* the actually available RAM size between addresses `base' and
. f n: J/ g7 X5 @% A* `base + maxsize'.) m6 r5 v0 Z! t' X- |
*/
% ]; Z) z: P& K- t8 Q$ L0 b# c4 W2 b! Plong get_ram_size(long *base, long maxsize)
9 A: c! n$ Z9 @, |+ a* }5 O4 {" {{
5 Z6 t* J+ ~+ ? g+ `/ ~$ T volatile long *addr;6 L% v$ p& s" }1 L. h0 g
long save[32];
4 J8 Y2 F+ j* S { q8 b$ U long cnt;! V4 H n7 B: u8 U+ [. ~+ b" J
long val;: z9 i* w# K3 [6 f
long size;
, b; c% I8 T2 V4 `- ~) P/ Y4 p" ~ int i = 0;. K! C+ n2 }6 F3 f" a" M
0 f8 `1 O; J7 z0 f3 ?# R1 L
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {. H# [$ i% K* ~ l
addr = base + cnt; /* pointer arith! */$ S9 a. h: S# P) ~
sync ();
% X/ \. m T2 Y" X& b save[i++] = *addr;* U: K, A$ W! d/ h2 c
sync ();
/ [; t. n9 S% }# Z7 {4 H) {+ j' y *addr = ~cnt;
9 U% S) o# n+ w1 O# r }0 V+ n( H% i( N: h) Q, Q7 p
& q8 o4 m, x ~% `7 D addr = base;
$ Y/ t9 Q% B/ ?+ A/ V8 l sync ();" y; z' G) D: ]" Q2 P* d
save = *addr;
1 d/ y1 x7 J7 K0 \7 O( b sync ();
! j9 y# a- G! Z) G! a8 F" } *addr = 0;
7 Z: P1 z8 i0 V( s" H' ?4 |% p8 g
9 E: J+ o/ M% e: |" k8 @2 A1 L sync ();" b' a2 y% K0 \1 u! x
if ((val = *addr) != 0) {
/ ~9 o2 H/ i" y9 i /* Restore the original data before leaving the function.' R( R' g) I: I) @& k# W
*/
; G) t6 K, n3 X) W sync ();& T6 e: R1 E: |, F
*addr = save;
( G/ b2 U9 y) m: [7 t6 D3 O3 P for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
" H" f- o' E8 G* T+ B1 K addr = base + cnt;
' N4 B2 Y0 y9 z7 E7 l3 E sync ();- z0 z6 ]6 H) E6 @
*addr = save[--i];0 [! M8 t V& E, g
}
; m% r5 P: ?8 k( D7 t& `* u* e return (0);6 Q6 E' o7 g- I" R
}
! S, d, Z' ~8 Y0 ~; o8 S
. U0 @( L* W4 P+ u G- N for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
) g: y# N1 L: I- } addr = base + cnt; /* pointer arith! */
* z1 g% _' h, s val = *addr;
- z A* _5 W1 h( M6 K% Z *addr = save[--i];
7 ^ o3 K+ F" Z p$ y. w2 G if (val != ~cnt) {9 X7 J/ t/ ~, C, S: ?3 R
size = cnt * sizeof (long);2 L7 h( d6 V/ L- y. `+ w
/* Restore the original data before leaving the function.: _; N8 o/ V) C# t# o$ [# z
*/
9 x1 j! F i# Q- W( f5 T! \ for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {' Z: O# O( J% b
addr = base + cnt;
# j9 ~( _8 [: e; \! s *addr = save[--i];' r8 B9 X) I' H# [2 y
}: b i7 p: b: g, J( B
return (size);/ w3 F* d. s! D! P
}5 @9 l' g& T& Q D$ T
}5 `* ?3 Q5 ^# m/ ?
b% J& V9 L) J! P+ t- ?, b! }
return (maxsize);
' w1 w& r; q: J- V5 I% D} c9 _+ K1 T, s4 I9 Q
int dram_init(void): f6 p* e; h' P
{( l5 |# T" x. \. c
/* dram_init must store complete ramsize in gd->ram_size */
: P3 ?, {* l8 | gd->ram_size = get_ram_size(/ J& o3 g7 j$ I) L
(void *)CONFIG_SYS_SDRAM_BASE,* \5 A6 U3 g9 i% R: W; w
CONFIG_MAX_RAM_BANK_SIZE);
+ |- H, }% e* D! f5 N9 n; g1 D- e return 0;; y3 Y* E) m& v% u5 p& C8 Q$ ?
}# `; E$ l5 y& Z
0 n) ^0 I/ V) @" Z2 x T- {; J5 H
; @$ y% l9 \8 Z/ l n0 @. t; \
) s% F% ^4 H B5 F2 f% i* y% A; }+ y `
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
$ P# [" Y( j- [/ h8 Z
6 m: [; E6 ?3 T, \! o- i3 k8 g- X) Z+ p) G1 {% @
/ ]* I& a; ^& X- U |
|