|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
! H6 y' y1 Q6 y- v% Z0 M0 R( h/*5 k# G! \! \+ l# h! {
* Check memory range for valid RAM. A simple memory test determines
) t( k1 _! O8 n* the actually available RAM size between addresses `base' and
. [9 k/ `+ V9 J( ~* N* `base + maxsize'.% a; P$ c! |1 C
*/% ^ ?5 S; ~5 T6 c
long get_ram_size(long *base, long maxsize)
$ J3 e; S4 B- n' z; c- V, O{
" v# l! P2 ~% Z! j; f" r% j' d volatile long *addr;
9 |) ]5 d$ q' c4 A$ h: M3 s long save[32];$ D( p( F v6 Q- c
long cnt;# E1 d' L0 P' f; T
long val;% b \# I' d5 @
long size;% S5 Q* d" d- l$ n
int i = 0;
1 d5 U( f# W# N7 z7 Q* ^; Z4 s
. ^6 J4 D5 v( B. w for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {% P& t, e9 E5 V
addr = base + cnt; /* pointer arith! */# k1 Y9 y4 B- ?( K9 U: f
sync ();
3 p+ ?& @; I7 k0 I6 [' |: k3 ] save[i++] = *addr;
# F* O0 X5 G9 ?7 o$ F( i sync ();' R" M! `; t9 R' C- O# W$ \7 H
*addr = ~cnt;1 N Q! ?9 J) Y8 Z" j) m& {
}- t" \8 k9 P1 j+ P' j; Y4 ]
' X% x0 u& ~& c7 M& l0 {* r o; J
addr = base;
5 R1 A6 V- f+ ]7 W2 B sync ();& _1 V% g) ^5 F1 t5 a2 p8 Z* ?
save = *addr;
. B- f4 A, X' |; ^, r' V sync ();/ U6 i7 o5 X; s* k1 ^- g4 K
*addr = 0;( M2 m: S1 m. a1 u! t9 I7 Y) U) b
N4 w2 S6 w3 V# Y J* J9 T
sync ();5 C/ d' ]4 ~0 q5 L2 L* N
if ((val = *addr) != 0) {, ]: g! ?# M7 h! h0 {5 a1 z0 v& c
/* Restore the original data before leaving the function.
& c% ]1 k% O0 U; C+ _9 x */
4 l* o$ ?* S1 O0 v' g$ r- X0 @8 ^ sync ();
/ L/ I. S" {2 a7 f. j [- y. w, n *addr = save;
* L7 w; d! O8 D" K7 \ for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
& W9 ~5 T+ g) N addr = base + cnt;
, o$ U3 ?/ A# a; ]( p sync ();: f( ~9 k) d* s2 T! a
*addr = save[--i];. W1 P) T/ _% _0 {0 w# G
}" F) e9 r1 ~' v3 f( u
return (0); @; T+ {$ r1 j6 Q, B2 \+ I
}. ?9 s$ G U8 w1 i7 R
t+ u. {" b, y
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {* Z1 m! P3 w; M! J2 b9 I
addr = base + cnt; /* pointer arith! */
5 X0 f/ m+ k2 ]7 i' X4 P val = *addr;& q7 c6 q) z X1 W) k& f3 C
*addr = save[--i];9 c, G% S- f# S- @$ H' C0 x: x8 m
if (val != ~cnt) {5 X2 {7 _$ V! R7 P2 S- I/ h
size = cnt * sizeof (long);
; ^+ G7 s, b, I" \* Y /* Restore the original data before leaving the function.8 _1 j5 v8 `/ `: B1 k+ H1 `
*/- L" m2 V4 F8 M' Y$ T
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
8 Z. i. _5 _' ?5 a" S1 o addr = base + cnt;; P$ B# u! b% X* I/ D# G4 V2 F
*addr = save[--i];
8 o' O+ n, k0 I+ R7 R }
' E; o% A/ G' l% `; }, o" H* \- ? return (size);& s v3 ]8 R- W u8 q) M! o# j" G
}
. [% j/ o( t7 C2 _- [# d% B }. s a( l" j" w0 b0 O0 C
4 K' T! M) b6 F, v- |0 c2 X return (maxsize);1 v h+ a8 v$ h6 [" H& ^2 T. r9 m* X
}
; x- f! V; ~- ?8 F* n, Y3 |int dram_init(void). K K! C4 i: y: |# H# |
{
; f6 S# |: B# i0 d /* dram_init must store complete ramsize in gd->ram_size */* K* b! F- ]9 M5 P1 V7 \9 h/ v2 A: ^/ Y
gd->ram_size = get_ram_size( k I; o& ~( F# x2 Z" X
(void *)CONFIG_SYS_SDRAM_BASE,
7 y% ^6 q% `2 \5 Z6 T/ u- M% { CONFIG_MAX_RAM_BANK_SIZE);
( {& k3 N+ Q" a) e' o( ] return 0;" {$ \2 Y$ {7 X
}
0 ?: k% H5 k5 [" f6 \" Y" C* v7 Y `* b3 a
6 n. B& P- s% [' G; D X* Y
% C) j# y& Y! ]3 u% y( j( V
2 A4 b% N/ S7 b7 ?
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
- n3 T- o& s# }2 q h, y+ c! _3 ]9 X
! K! ~% A$ N- L$ o0 C, P$ u& p! L
+ w% P3 A* S! v" v3 B9 @* J
|
|