|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:& _" k3 a0 }) v' h' |
/*
+ d5 c; w0 D/ Q" a* Check memory range for valid RAM. A simple memory test determines
/ V i* f/ V) v- R1 Y% i* the actually available RAM size between addresses `base' and* y7 }" V; ]- B
* `base + maxsize'.* w/ l- J# ^9 L5 l& O! a
*/& l+ ]9 y" P: u \0 O1 L1 C4 g4 X$ `) V/ E
long get_ram_size(long *base, long maxsize)2 U0 p: b7 |+ b: r6 P7 M( I
{
; h, _' Q: |% U6 A7 J; p+ f2 H volatile long *addr;$ O* T( `# L% V: }7 h! a; O5 O t8 w4 `
long save[32];3 M d7 T' {& n# K6 {+ d0 G8 q, F6 I
long cnt;/ A1 k0 p& G+ t; ~& I+ s
long val; s0 f8 W8 ?8 W: {7 Y4 O
long size;
4 `" Y m2 R* ^ int i = 0;
0 s, A# A. m4 K
* z$ h8 ?: k) I9 h' s7 A; I" d6 l) H for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
. O( n' q! o/ v+ M0 k. _$ s addr = base + cnt; /* pointer arith! */
0 L6 G2 b5 v: c/ U$ v7 ~: E sync ();
* _2 }) [% L/ o, V9 B1 ?& _ save[i++] = *addr;7 Z0 \- m4 q! |6 Z, n! ^% Y
sync ();1 n V/ a! F, O( o. i; Y
*addr = ~cnt;8 X0 o/ {# H2 |) p
}0 g( r. F. ~# o2 S5 q9 x1 E
! o8 H" Q( L# i- z4 b( O2 d addr = base;
& E' s4 _/ |) q4 X! ]! m0 ? sync ();, ]3 [2 A% ]9 E4 C
save = *addr;/ S8 L3 P% Q H6 M/ W) ]
sync ();
1 O+ q; _: @9 [, Y *addr = 0;& [( P2 V h) h$ D
1 M' Q8 [8 U/ f: O/ y4 B! S sync ();
- P5 Z8 g( v# H8 O- `; U' _9 A% U if ((val = *addr) != 0) {; `& |) c# b; \
/* Restore the original data before leaving the function.
6 `+ S. l8 D. ` */
9 F, _+ j" c6 i sync ();
# l& W% x/ [1 ? H *addr = save;
, K: @: }) ~% `! X; h. [1 c" |0 _ for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {5 {- J6 U2 t: E6 Y. @3 s7 [
addr = base + cnt;
4 s L, q! {* W- V1 M sync ();# o4 k# o! } M, l5 m5 |
*addr = save[--i];; K( [- x0 A7 ` n) ~2 k" |2 D3 ~
}
7 T2 x5 V( I X& Y/ Z4 y7 f" i6 X return (0);
, J- Q* `* f0 }- i/ i' S6 x }
# y4 [! v, V% ^8 }8 s/ n- O7 Q7 O% a- h, W
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {( r/ M7 H/ P1 U2 W3 v
addr = base + cnt; /* pointer arith! */8 t) ?% C I7 |/ d9 I. {
val = *addr;
# z8 E# {( T# \% U *addr = save[--i];4 e! C* Q( ~& t4 b2 P
if (val != ~cnt) {
7 X/ C: c; H" N size = cnt * sizeof (long);3 T% T+ m1 v8 e1 a# u+ M: q2 a
/* Restore the original data before leaving the function.
) r$ _9 ]- G) G. H% l' h8 { */
4 ~+ ?& ^7 X6 z. N2 L9 C* j for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
/ @( X2 j( u# | addr = base + cnt;
+ v9 p1 z( N" v( j! q& R *addr = save[--i];$ b9 s! E' c% P
}
- w* \2 D2 V! w& S* p return (size); L5 x2 s- X: M
}- i0 S# @- W- J. T
}
$ o- g. [" `& A! C- F# D1 \, Y
5 e3 n7 W) G# c& B' D return (maxsize);
" r5 j/ u" n0 C6 W& \}" H7 k& n* d3 g8 i
int dram_init(void)) s' d& G) R2 w
{
* b. P+ e* y- N /* dram_init must store complete ramsize in gd->ram_size */( l7 F& E: e6 Y' j4 u
gd->ram_size = get_ram_size(1 p- }+ V# p! K" i/ p) E- l5 s
(void *)CONFIG_SYS_SDRAM_BASE,8 Q2 Z% f, m& e) H, K5 k! n5 U
CONFIG_MAX_RAM_BANK_SIZE);3 P0 p9 |6 }4 J5 v$ G/ a* D
return 0;
5 y# o4 l8 H8 i6 P# i0 g}
# n4 ?) w5 [% f d
2 b# F+ R# u0 u* X$ ]
; D. L& g2 `/ q" ?5 \( }7 {) O' A) M7 {+ [; y, `" R( E8 n
( p/ i3 J, s, F g8 Y- N6 d
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
6 q, W7 z% N$ W
$ P! D1 w8 f, Y, I7 k3 v+ G, p) q: D) u) H/ v6 P
6 h4 P' z" o7 E& z' A! k% K( R |
|