|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:9 B# N$ a( w- ?0 i4 y* Q
/*
' |3 f B) G' |( G: l* Check memory range for valid RAM. A simple memory test determines1 G' X& `' n U* }# {+ g
* the actually available RAM size between addresses `base' and
. u( w2 I/ @0 v) Z8 i% s* `base + maxsize'.
1 R/ [: ?! N3 V6 }% X*/+ G: {0 c2 `7 d) J6 q1 E
long get_ram_size(long *base, long maxsize)
! j- q, o z, c- Z% P{: p6 A( P: q o$ O" r+ k6 b7 i' m6 i/ ^0 }
volatile long *addr;* r: k/ g. I1 {2 q0 l. @' w
long save[32];; N r3 d+ p6 _. s' |7 V
long cnt;
: B7 [7 d0 c5 j. p: D+ T& T long val;* h& e8 [) U, Z, S
long size;
! G4 Y: |0 u Q3 Y% K, Q int i = 0;- d" P9 @/ r% P9 q# g/ A# e
7 V7 a! Z: q+ G
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {9 D: D$ d( E7 D9 V$ m
addr = base + cnt; /* pointer arith! */6 Q v. v, l( c
sync ();
7 j) Q/ K1 o' q/ G save[i++] = *addr;. s: F' O: u2 R
sync ();6 G8 K7 s5 t/ M' G7 p3 L
*addr = ~cnt;) L2 L: q' G& p0 L6 T
}
1 p' F3 {+ A3 u. y9 C& H0 n6 }
8 p( ]* C3 a- B) g addr = base;( N, p4 \8 ]- q
sync ();3 n/ g8 ^8 x, I% R& I
save = *addr;4 O9 @4 G2 X' X+ `& }3 y
sync ();
' @% h- j0 C. X% m( S, X *addr = 0;. F$ s' X# [% ^$ n" A* f
J R n9 ~/ \8 M5 K/ T: @; Z sync ();
- |2 ]# O% U" Z( B* _4 w1 r if ((val = *addr) != 0) {" t7 ?+ F$ p$ B1 I, m
/* Restore the original data before leaving the function.
; u9 Y" U: R/ t4 ~+ L */
0 t# l' [! w. _, a5 i. [' E sync ();$ |6 A( p6 `& g9 R, U% m. [
*addr = save;1 V; P$ Z9 y0 Y7 F, A
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
+ S5 h% |4 o- F+ r$ R9 E addr = base + cnt;; D# g4 g2 r4 c' d' m _9 G5 R( ]3 W
sync ();
( h1 o K, p: T# T& t. C *addr = save[--i];
( P- L+ @8 K+ z- L7 r }
: M/ `1 M8 r3 d9 X4 }, @ return (0);
! c3 c* q2 e I9 u* v) g. n) ` }
. V E% D* {. Q8 h" i
( o: x0 C- z8 \+ B for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {1 z( C: s7 C# k, e) b0 Z
addr = base + cnt; /* pointer arith! */
% O( H; H1 [3 ] val = *addr;- f* O/ q9 I9 m& H k
*addr = save[--i];( M/ O4 R) }& r# b/ x l/ M
if (val != ~cnt) {9 j `" Q: ?) u
size = cnt * sizeof (long);
% S( U) u3 r$ l- ~8 T /* Restore the original data before leaving the function.9 I1 z$ g& F: |
*/
( o; @% a: @5 {9 A, s" ?, r for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
- F$ g8 ]$ M9 j* L# }. x+ } addr = base + cnt;
! c B- n) [: L% r* Q *addr = save[--i];
$ w* T) h+ V: ~% _ }5 n1 m" y0 d5 ^2 O. f2 T" j
return (size);3 r- d' |/ x3 Z4 v
}; J& K3 F9 C, O( F" S/ o' O
}5 k# C$ t7 l6 Q+ R7 D6 U) P% m
( I2 j2 P# [5 Q- N: u% D( f1 n% q" | return (maxsize);2 X' {* S9 A Y( j" r
}5 v! J6 W9 t4 d
int dram_init(void)
! G2 O/ z. \2 i{: u) k) x# l% W6 P5 ^0 [
/* dram_init must store complete ramsize in gd->ram_size */+ i+ J% v; Z$ h4 M: I$ ]9 x# c7 ?4 l
gd->ram_size = get_ram_size(
W$ c" I' U Z: d (void *)CONFIG_SYS_SDRAM_BASE," _; Y* o5 \- U5 x: t
CONFIG_MAX_RAM_BANK_SIZE);* F& Y; Q, }# I1 Q/ g2 W
return 0;
. `7 `+ E& {' ~$ d m}
; A8 o" v- o1 o; A0 Z1 K" x1 j, W7 E. ]# h- _
" O; I" i( i- Z# t* I2 y; g
; s% h+ F7 m; A3 m/ a Q
' E2 M4 n- L* T% c8 |( w' nFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!2 o6 T+ Y5 U0 C& B6 @# S* {3 t
3 n+ r P: `5 H) ?. {8 A" r7 @$ i. S0 {; A
$ y- _7 t1 \$ X4 N- ~
|
|