|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:6 V/ B+ x1 n; C) F( }
/*
6 y/ r' Q6 Q& \+ B* h* Check memory range for valid RAM. A simple memory test determines
+ V* Q6 o( g5 r! Z& k5 r3 ]% \* the actually available RAM size between addresses `base' and1 _- J: U! x# K [
* `base + maxsize'.
+ ~3 U* |; O# P7 E! A9 }, T8 ~9 d*/8 O) g9 y+ s3 k8 G
long get_ram_size(long *base, long maxsize)6 e0 |% U: a1 J) {
{
( |' f9 x& O4 n volatile long *addr;# [: B* V9 J& i7 D1 e
long save[32];
' n$ N: m* y: d9 j- J) P/ C long cnt;
! `5 o! O: F) ~8 ~' g long val;) Z4 \# X# u( S& I4 i' b7 b
long size;2 A% Z4 P9 q0 o8 L d! G5 c$ p h
int i = 0;* Y: i* \- I. l: }* m7 y" r
" V$ x# g- W* v& f7 @% S" b7 V- X for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
" w2 e$ t4 g1 f) O4 m, Z* ] addr = base + cnt; /* pointer arith! */$ d0 t5 L1 b6 D5 R+ y5 p/ |1 q
sync ();+ K9 j, C) {* ]3 g
save[i++] = *addr;
' M4 V) P# Y( a0 x7 M8 Q sync ();
B0 O" H& O( T" @6 G *addr = ~cnt;
. t8 b& S+ O; I# s0 N* o }
0 A! w' N; [9 s- I' J' m, s1 U" S' \6 L
addr = base;) l3 {% E* d. m- m: Y) _0 w9 F; @
sync ();+ d* H- q2 o% S$ P: T) E3 { n# `; L
save = *addr; E7 n- M/ [: f! p% t* y; o
sync ();4 t1 D, T7 B$ I* Z5 a2 L2 p
*addr = 0;
0 `! c1 Q6 W" D. Q$ r9 U2 d1 q4 {* Y1 k9 U- T) |
sync ();" i! _% ~2 Q2 s9 p9 v) o
if ((val = *addr) != 0) {" q) ] W" X% I! c
/* Restore the original data before leaving the function.
& S/ h! g: q# b+ E! r5 K2 R" f4 c */5 l; x* L6 h) g! J
sync ();$ y# }) T- [3 o
*addr = save;0 V/ m1 C5 u9 H. I8 {4 E
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {; r' J, ~9 f! I0 p/ U3 Z
addr = base + cnt;/ z( j0 _4 {; c8 q
sync ();
( g0 u+ ~' N% D9 o/ W; M% r8 ?- Y *addr = save[--i];
. y: Y9 J2 d# v8 u% d8 I. q }: t* \6 R: G n% H1 w3 Y+ ~+ ~ J
return (0);0 o( J T+ Y. Y9 n. i( x1 }6 U
}
! F3 c6 t, z- p" e) e
( o; |- `; j' s6 F2 T$ J9 e; z3 P for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {3 _. R: L: ] S# m6 N
addr = base + cnt; /* pointer arith! */
) F) C5 ^+ J7 C) j) }* P4 ^6 C val = *addr;
4 Q/ ?3 j5 i1 _ *addr = save[--i];# J. e6 i% l& s, [
if (val != ~cnt) {
6 b! r( H) z3 j7 V4 S2 b size = cnt * sizeof (long);! V+ \$ \& p' J$ I9 |
/* Restore the original data before leaving the function.( i2 H2 s' W' b! ~: I5 V9 f; R& \
*/
, C; r7 g6 P! S8 W$ T: k for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
7 I- }( k- \# c- Y5 R9 K addr = base + cnt;/ h x2 J2 z! U9 c# e- S' c' A
*addr = save[--i];
' I2 @% o# k, G: b. D; V; D }4 A4 r8 b+ v* F: ~& A' H7 v
return (size);& J z9 j* T- o' W# f
}
6 G4 f! n9 q* H$ M }
7 Y" d m- d2 s* Z5 q9 v& J) a1 y- o1 M4 i5 _8 k
return (maxsize);
6 f) d3 U/ `" h. @$ Q}# o! @8 [* h5 I* o/ x
int dram_init(void)
: {3 o: ?" |" l+ }/ M8 v! E{. Z3 x; _! ~+ B# z8 [. V) ~8 ?
/* dram_init must store complete ramsize in gd->ram_size */
8 m9 e( B0 I1 M% U6 k gd->ram_size = get_ram_size(
7 g% c- v: U2 J+ ^; Y I7 {# ^$ ] (void *)CONFIG_SYS_SDRAM_BASE,* K( q2 }8 P6 c: t4 T8 V y' r
CONFIG_MAX_RAM_BANK_SIZE);1 E8 T# y6 g& k* ^- k. R" l
return 0;
& ~) Q3 a/ J; E}
- N, ~( v$ K' d, I; ]3 @& e% p1 V
$ s ?$ i3 D! {; ^" o8 G- W# `& s5 g! {! V+ e- T! q* y
; m- j. {6 k; p7 Z. j! F% q
! _$ A V1 P7 d4 \, YFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!! G1 u" u4 s% [! |
4 l5 t4 K1 E0 B" S4 g# j. \" r
) G! g- E8 T' O6 J8 H9 P. q* m' C$ u+ [9 d- H9 T
|
|