|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
, O, L: S& f7 [: G" _- o. h) C+ G/*" c7 t4 T0 F* y0 Z
* Check memory range for valid RAM. A simple memory test determines
. z. c- m, u, v" {! p* the actually available RAM size between addresses `base' and
I6 o7 H0 T* h! d. ?' ]* `base + maxsize'.
5 H% u/ e/ H9 W*/8 f; B. Y1 P2 ]* L9 m
long get_ram_size(long *base, long maxsize)
8 G" X' ~, I0 Q2 J1 d, R4 {{
$ k1 X$ U' }8 x g, K8 h" Z volatile long *addr;
) ]7 Y$ v4 r% y long save[32];; u; i( { P) A1 S7 q6 h" y
long cnt;* g* l8 _2 s- G9 {8 a; N
long val;
8 _( h/ g2 T% ]" _4 X; r4 R long size;# z- L7 A9 v' D( g! x3 G4 w( d, i* m3 q
int i = 0;3 x' m8 F& k) `0 S, L- w' P5 K* B
: G. Q" ^3 I( h5 w/ w! ` for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {8 E) g* Q( C5 y* j( Q. r
addr = base + cnt; /* pointer arith! */
, ~* B' D) i) i( p sync ();
" M. `: W: w0 q- q3 I5 x) Y& R save[i++] = *addr;3 G' x# l( U! C
sync ();# p2 {3 a0 ?1 z8 C! D! V6 Q$ U1 E
*addr = ~cnt;* b% x$ S+ n3 j* S
}& q1 c& W. u! N* m
3 X5 ^* o1 _9 U% ^. b' z+ ? addr = base;
, {- l8 y; b# l. Y# c6 j' F( t9 ^ sync ();
2 Y' g% X2 w9 [+ g( g; B save = *addr;& \# Y; J. X, r4 a0 b
sync ();8 W: t* P4 S, ]/ Q
*addr = 0;( L* }# I- Q, m1 y. m2 E
: H: f3 g0 @ [: k0 ?
sync ();/ y4 I; a+ p& Z$ c7 e g$ @
if ((val = *addr) != 0) {- G4 `" {# A1 W! I D
/* Restore the original data before leaving the function.' Z) z% t) Q& w; U
*/8 B$ }2 E. M: @: ^1 t
sync ();
7 z# H7 g( h/ Q- W: k9 R2 Z1 T *addr = save;6 }* n' C5 x6 ]& `1 @ ]. u3 v# F# v
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
. ]; {' T: n; I( K addr = base + cnt;% V0 z4 f& w( D* I# o& Q& V
sync ();/ C$ @) H( [9 z3 K
*addr = save[--i];
" U! s" r( Y. Q- m) e }+ P8 R* @0 l+ T' |1 C1 u
return (0);
) {# K3 S/ D' \7 M9 ]7 N }: m. f. J: O" I$ j
! u( R# T O# R% D
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {3 _( R$ r E) D' ?# F% Y( f) j
addr = base + cnt; /* pointer arith! */4 j+ N. J+ o: W& E p6 Q0 ?& [
val = *addr;
1 }% m2 c6 k. e5 Z *addr = save[--i];* Y- i! h% a( T) g1 A4 m% Q7 ]
if (val != ~cnt) {3 t7 c! `0 N! d3 L4 t
size = cnt * sizeof (long);
, y9 U7 e+ ]/ d7 U /* Restore the original data before leaving the function.3 U' Z6 R' {1 M- v
*/5 N+ o6 R ^3 N5 K
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
4 H: H( `% w$ d addr = base + cnt;
7 x4 Z# p9 { ^) Q" e- P *addr = save[--i];
# x5 A/ P8 J5 Q }3 m E; e2 N& d- V6 B
return (size);
# M3 b% j2 m, B) M* t: X$ r }
, Q9 E" d# m/ x# ~, G }
$ a% M1 G1 _" L$ F& C) M# d' T* K: J6 S' R+ R9 f
return (maxsize);$ t: X4 |6 V V8 }; O+ j
}
$ r: d& `; ^( d+ S+ }' n# ]int dram_init(void)& A; B: y! O2 h+ L6 {) O
{
" }' V) l, f; }% ?# f /* dram_init must store complete ramsize in gd->ram_size */
1 C8 `# C! P. ]6 L: Q+ f2 c9 u gd->ram_size = get_ram_size(# d' Y4 B) O) |9 A
(void *)CONFIG_SYS_SDRAM_BASE,: B q# t6 m! x4 F
CONFIG_MAX_RAM_BANK_SIZE);& Z+ V9 i! O" \) u$ |2 L
return 0;" x. _0 d) D# [% S
}6 Z2 y! `# {6 l1 d6 e- S+ j" [
0 J3 I: L1 r, F" i
- L5 U2 {" M% ^& T4 j+ f t$ u
4 m; ~0 @, q- w
( C+ e7 t. d( x" j; LFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
/ `7 s) ]% j3 ?" u' d+ Q, X6 F/ q+ z z3 ]2 m
6 S* S. U0 y6 c! _
* h: y$ |+ g! p7 T, a |
|