|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:% L3 e* S/ n6 P' j1 p, w* M) r' E4 @
/*
% E6 Y5 v' [& ?1 m1 j1 j, f* Y* Check memory range for valid RAM. A simple memory test determines# b/ j" j0 i( L0 d* |7 T% f4 Z- h
* the actually available RAM size between addresses `base' and
+ y, G7 i( C& z) ~/ L% d$ T4 ^* `base + maxsize'.5 N9 r7 V, I" c
*/
6 Z* ]1 q& O' `long get_ram_size(long *base, long maxsize)
$ z1 r8 Z8 P \! O0 ]: s* y{4 a3 M! G* K/ z
volatile long *addr;
- ]3 B9 z/ B% V+ P* B) T3 t long save[32];. t8 D. {# G [* i7 ` E8 |
long cnt;
! f/ ?- F' \+ z long val;
) Y3 n! I6 `, Y2 o: \9 R long size;
4 v/ @! }( u0 ^ int i = 0;
$ a- H7 b* O4 H% R! n6 ]9 I3 Y K" | C$ W- D
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {% a+ S$ H6 S0 x. l+ T) u0 ~
addr = base + cnt; /* pointer arith! */
$ d; p( i: w1 s: t sync ();, _: _. w7 C Y7 E, {! C+ U
save[i++] = *addr;2 a% |. \2 E2 v2 _. a D1 E
sync ();
& r" l+ h, r& O/ U) V! y" A7 l7 A *addr = ~cnt;0 _0 Z; f, p p
}
, @: D/ f4 ^5 }: v7 c3 d
$ k$ e7 \& T1 | ~( k addr = base;
" [4 `9 A) W$ }- Q1 E1 Y sync ();
' o$ d/ H' R. l) P save = *addr;
6 Q- V8 r$ s' D" p8 k* C3 M sync ();, O$ ?) F+ e4 Q) E& \. f5 V- h/ v
*addr = 0;) C5 ^; S# ]* @0 q
: Y/ B9 o0 c, c& R sync ();
9 T- o+ J0 S! } H, Y) U7 { if ((val = *addr) != 0) {. o& y' c5 C% j5 q
/* Restore the original data before leaving the function.# F7 @- s, c7 z/ F- e* R3 R! R
*/
6 m5 c6 y! V) \, J sync ();9 |$ U: |1 h, v% Q2 A, o
*addr = save;
& r z6 S' d" }4 `% R) [" ? for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {# a* L5 A% y, b* m, U, o# [" Q
addr = base + cnt;* Y5 |, b1 l, Y. u j# q
sync ();) ]" l: J4 h6 r: h1 @7 g+ n
*addr = save[--i];
: [5 H0 Z0 y/ a8 O8 @& k }* H. y& K, ^' x& O' x
return (0);0 o" H* u0 ?$ J- ]4 ^- D8 C
}7 j8 A7 |6 m1 }
' H5 X7 \5 H9 g, G) I for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
( y+ {/ D/ f7 ]1 Z addr = base + cnt; /* pointer arith! */
4 h* g* F+ u( D9 G+ I val = *addr; U5 u& [3 F( q. R# x
*addr = save[--i];
/ M( t, J1 U( H if (val != ~cnt) {
$ z5 ?4 H$ }) Z- _ x" R+ Q: r size = cnt * sizeof (long);
+ g: g P1 m, @+ _ /* Restore the original data before leaving the function.* g+ y% w) Z% B5 D
*/
0 ~" {0 `6 z* @) d for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {3 g9 ?9 C5 K8 c1 h9 ^) }
addr = base + cnt;2 Z; ^* I5 r# U4 b! M" [
*addr = save[--i];
7 l8 K' d5 K' a }
4 ~, |- M+ @9 h$ T3 h' t* I return (size);% Y! S2 d' C' ]$ i& j% \. J1 d6 a( D
}9 U6 [% n( J4 M% J9 m, [3 K2 a% h
}
! d5 ]- `5 u E1 `" Q% T7 M3 L4 \, X4 n
return (maxsize);: v1 n6 t# y) W2 E# `& v
}( J0 ~2 K. r( U2 U2 i
int dram_init(void)
1 N4 }6 Q, H+ K F* D- v{
9 F% L) U/ G7 r S" P /* dram_init must store complete ramsize in gd->ram_size */2 i! a1 y4 E; p- V7 C! }+ R4 m) L
gd->ram_size = get_ram_size(
' [, Q* C# _+ P, l7 L (void *)CONFIG_SYS_SDRAM_BASE,
7 O/ X& U t6 Q7 a# W CONFIG_MAX_RAM_BANK_SIZE);% t7 I! `* p/ K( M9 @8 W! l% A0 ~
return 0;
% f% _% i: f* X& x}$ ^& E# d$ Q" \$ N8 N p8 d( `
( @/ {+ z& t! J2 d6 l/ `5 x
! h: Y0 M8 \# r5 J0 T1 P' R+ u
# _% C" j7 r( D4 w2 p
2 Y. I/ Q/ O* F2 i, F8 ^FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
; k( f% u9 b4 w1 Q+ v$ H
* j# }# n* S4 v. ^9 ]. ?6 U x" @7 Y* A
/ W1 j& S4 P% P- Y& @, ] |
|