|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
! {9 }$ Z. o% i' U, y# [/*
* o5 |& o; e* H2 Q) ]( x* h: k* Check memory range for valid RAM. A simple memory test determines
: T; r( \/ b# O3 `( t* the actually available RAM size between addresses `base' and1 r8 A+ E' @5 C3 t) l' y6 G
* `base + maxsize'.
, W* }3 F9 x9 D X# j( D*/5 \: p* u# w: o( M- e- w/ d; o
long get_ram_size(long *base, long maxsize)
) b; p4 V# K! V$ Y/ e. `$ {) ^: s. |{7 `$ i8 W% h8 v m Y
volatile long *addr;
. x' X1 e8 |* u" E' e long save[32];
4 D0 @. [( P+ s- Q4 ?( @5 z8 \ long cnt;
( Z: U7 k- ^0 E2 D! P; | long val; k0 Q( Z' x: S8 U( C8 A
long size;5 G* Y s! H1 [) s
int i = 0;9 v& Z$ R0 G9 M
$ s [% m, K3 S# o- s
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
9 A# T- g% @' ~! F4 I2 | addr = base + cnt; /* pointer arith! */
* |) V( Y j. H) q* K sync ();
3 {% a* U$ p- L+ h. w save[i++] = *addr;
) ] D! i$ w8 J sync ();
) l: s/ q8 C2 ?) J4 w *addr = ~cnt;
. R% h+ _. i4 f, x }4 _. j1 q ]! j* f! l8 ]" N
: s) } j- I+ _3 Q1 R/ F1 Y2 n/ P addr = base;+ N$ W u8 T2 J1 B I0 K& @
sync ();& u0 t, R% y) U2 A! L
save = *addr;
: U" s" R! l$ O' F sync ();
* u! U2 x7 S1 V7 o H6 m8 b *addr = 0;0 O5 K. S9 p" ?
0 m- X( X3 B, D' @& K sync ();, m7 ~+ H( p Y9 D
if ((val = *addr) != 0) {
# }/ k2 a X5 P7 {# a* e /* Restore the original data before leaving the function.
% w, H" w- u4 t8 q- s" \" p& w */
8 b4 w' A* d9 N' u. ~ sync ();" F" P6 [, N" i' y, F5 n
*addr = save;8 _9 O% e' \, d$ \
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {/ w2 t3 J. h/ a9 `9 B& T( {
addr = base + cnt;
3 \$ ^0 D n! y2 m sync (); a, k6 h$ p& I- B- O
*addr = save[--i];
; {( ?# s8 x* j }
* Q0 @+ [8 T' I7 L) Z return (0);8 [. i1 w4 `5 F! X; A
}
: ` M! B% h- g; d8 @; |, ^% u' a% \1 g
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
4 N" G5 A& V/ Q6 Z! n4 T6 g: ~ addr = base + cnt; /* pointer arith! */
* J$ m, t, H+ x! l8 f6 z val = *addr;
; ^ @0 i# v4 h. }1 r% l *addr = save[--i]; X0 ~) Y, X; y2 W7 Z4 e/ ]
if (val != ~cnt) {
. |. ?' w' Q. c# ~9 W5 x size = cnt * sizeof (long);
( n6 G) i! P3 g /* Restore the original data before leaving the function.
8 B/ H1 u. t) {) s' Y */' d! f! {! U( S4 T1 s6 K% ^0 Z* l {
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+ A( o3 d: u2 c0 d addr = base + cnt;$ m) g% e% R$ h% ^( V
*addr = save[--i];" L. \3 P) S K3 s$ H
}) n* H0 D/ X7 A3 X- M
return (size);6 P! d( i9 Q0 s( w: h3 \2 ?& ]6 w
}
$ k* X/ g! }8 K: F% _2 s }7 O) b! `7 r3 G, d+ V
4 t" B# Y4 D7 D8 x9 r return (maxsize);
- |2 J$ y1 o6 {. Y- |, D}
+ d! c' ?4 n- b1 J5 c& {) ?% nint dram_init(void)6 f w# k0 I" f1 z. J9 `
{8 F5 x) L4 [+ q$ H) e+ m
/* dram_init must store complete ramsize in gd->ram_size */
O/ }% |' I# J gd->ram_size = get_ram_size(
+ a+ E6 u$ w1 d( ]0 H( Z (void *)CONFIG_SYS_SDRAM_BASE,
# B8 f' n2 w, ^# t7 s CONFIG_MAX_RAM_BANK_SIZE);/ ^8 ]. R5 x0 H( t9 c
return 0;3 N/ l7 p6 k5 b1 |6 g
}
' n5 }2 h, B8 L; _9 _- A! i* q' r5 B5 Y% U
8 G0 {, _/ H. `' k& s: I/ s9 p) n% s
5 ~2 F( L9 |; Z! q) _" o
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
5 A% u8 i( f8 p" ?4 l# b. n$ Z5 d
0 C3 D* V! c5 [. V
# x7 E4 n8 K- {' c# n
1 N1 O; u. h, o: C |
|