|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
2 | y) C3 K. _6 _9 W/*: F+ K8 }0 Z& Q# m
* Check memory range for valid RAM. A simple memory test determines
2 p; V/ @8 n" d* the actually available RAM size between addresses `base' and8 x) U* c/ y1 T4 A7 j- ?
* `base + maxsize'.8 W4 k+ `" T+ _5 o9 z
*/: t H4 \( ]' H. \& [; }7 h
long get_ram_size(long *base, long maxsize)$ [) q6 z7 v$ \. B8 s. q+ o- J
{3 h9 S5 W( C' z8 o
volatile long *addr;5 @1 U) ^1 @% i
long save[32];& R- i; f1 p3 ^6 O. m3 s$ `7 P
long cnt;/ k4 \6 w0 V% ~: I, a/ ~2 K4 t
long val;
9 W7 ]! }: F& {0 ?! ^. _ long size; I: G I; y* q9 S
int i = 0;
' _$ Y4 k. U7 O4 t0 v$ D% ~1 j, i+ F6 c
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
* _5 q( a, y: M9 Q! Z, n addr = base + cnt; /* pointer arith! */
3 j) ^! Q7 T6 n6 |6 { sync ();
: f( S e: W* e5 J save[i++] = *addr;
# P z* j& s2 M- C {' ` sync ();
, ]7 ~5 ^* V) d2 m *addr = ~cnt;# [* X* }& r( l! n8 f, m5 {6 |
}
4 p+ f) J) W# y( A" p0 J$ H3 C$ s6 g" a3 W2 l7 Q
addr = base;1 O u# ` m! n& I$ p
sync ();
& ?8 k# Z( I/ Q q% U( k/ C/ { save = *addr;" j, @* \/ V2 G+ ^. o# W
sync ();
, y9 J/ {7 B! t# S; d W9 d *addr = 0;& P! C: c0 u* Y& V
# t" C* A2 ?# m% r4 V sync ();9 ?7 t$ _& A/ B0 Y6 k
if ((val = *addr) != 0) {& w+ u) t: M2 m
/* Restore the original data before leaving the function.
+ j( `. ] k2 }# P* _! H$ g0 p2 z7 m */
$ z( G* O" A5 W sync ();
( X+ Y4 f6 m5 {) z *addr = save;
, I q* H8 \+ a& j for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
$ g- r) B5 j- F' i- I addr = base + cnt;
9 B% O8 H* T8 D3 w; y sync ();
- K6 M8 z, v: E9 k# \ }3 a *addr = save[--i];% \( n; l; L( g4 T y/ U' s
}
4 {/ G( e7 l( i# }- w- H, p7 ^ return (0);4 X' B T9 ]5 Q" U. t$ ^
}
& f; `2 H( M$ C. m ?
5 {. l) U. R; ^8 x for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {3 D* y: b9 ?3 r- B2 r
addr = base + cnt; /* pointer arith! */- I' Y! G) E$ `1 G
val = *addr;
$ v2 Q0 Z9 `" @! O9 s. T *addr = save[--i];- _. ^& Z6 L+ ?* C
if (val != ~cnt) {
) F2 V& ]8 z& ~- ? size = cnt * sizeof (long);3 f9 a7 J, @( @ q2 ]* j
/* Restore the original data before leaving the function.* h( d- u) Y% \( V
*/7 h( g9 X4 ^4 W+ s3 q) h
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
3 [5 x/ U3 _. J0 A8 b' P addr = base + cnt;6 N2 F. V; q, A! E
*addr = save[--i];2 B- f2 Y0 w/ ~' S6 D; w
}
8 {# [2 s+ h# ? return (size);
4 M' ^+ L ?4 l6 A2 m8 T0 S }/ k" I+ U# E- L) ^% ?
}! x* ~2 b) M T$ U/ v
+ N# L% E+ Z% ?% ?0 R; w6 ~- v7 \ return (maxsize);; T, Z5 u4 k' Y% N" b& x
}
( R! e9 ?% ?2 @0 P# _3 R, tint dram_init(void)4 T" j9 l$ n1 |
{
# J# |* ^' ?$ C# m /* dram_init must store complete ramsize in gd->ram_size */
' N- V; @% M6 S# [ gd->ram_size = get_ram_size(
4 U, c! m4 T, l (void *)CONFIG_SYS_SDRAM_BASE,
, r, m% u- i$ ]- J5 P2 D( l CONFIG_MAX_RAM_BANK_SIZE);: z7 f2 ^/ d2 b+ @
return 0; I$ ?1 n: L! z; J$ b4 _9 b0 l
} w8 a) g3 N' d2 O; T0 S$ o5 `
5 v' Q2 q- `9 n4 {
4 S. W4 ]2 o8 B$ t
/ p) u+ q7 [) q& _, v, @4 `9 J3 z& W( b5 h2 g+ Q7 ~
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
1 I. f" x3 H S4 Y
5 Y# N! n, U2 h7 L! O8 K
4 M" B! e, p6 F" h5 i. A3 [ R' [7 ?% Q! W4 S/ o
|
|