|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
1 q6 ^7 f/ \2 @ V/*" ]3 p. z% e* K* f% H0 C* m N
* Check memory range for valid RAM. A simple memory test determines0 M6 X1 J! o+ p. J3 G1 S( [
* the actually available RAM size between addresses `base' and
I* Z( F! @* `7 H) G, x- X* `base + maxsize'.
$ F- `: \' g. o: _* E, e' s*/
0 ^9 e4 ~" {) Qlong get_ram_size(long *base, long maxsize)$ o: x: y' j3 @( T4 W; ^
{ O( s, l* m9 C% y% Y) I+ T& F
volatile long *addr;
1 o3 J6 T, P" d- n long save[32];. K6 u1 g. }4 Q% f& q3 p; W
long cnt;
: n0 v% @( [% n, y; C long val;5 a8 O4 w5 H5 l- I- X4 |9 Y. J
long size;
! O6 O/ i9 A" a$ u7 O3 c int i = 0;. w7 |$ q; y4 |! B( B; d5 V& y
2 X- }9 a0 E$ _: t8 r% V# G# e for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
* D* V: p+ ?; O- Q5 \$ o addr = base + cnt; /* pointer arith! */
9 T, Q W' t& Z. [8 w8 E sync ();+ m" G; K* Y" c" Z+ D9 x; y6 Y9 S% |
save[i++] = *addr;9 k0 c+ [1 e4 A# ~. W: X3 _; _) {+ C
sync ();0 I' }- W! G- {# F5 q8 [ O
*addr = ~cnt;, Z! v- C2 n' `, Q
}
5 a; z [% `3 }2 R w! s, d/ G) Z8 k- J/ Y8 |
addr = base;
0 X0 Z o/ z& ~* M/ d sync ();
+ y2 ^- f; E# d save = *addr;: U$ ^+ {% J' ^ z) j9 F' p
sync ();% ~9 N% X* D4 G7 `( N" j) u
*addr = 0;8 l' v! @' k0 `; Y2 Z! d: e9 r
0 G8 N! q& d6 Z. }/ t1 \
sync ();; _$ u1 T4 I( U
if ((val = *addr) != 0) {$ K" j9 @- L* l8 N3 k
/* Restore the original data before leaving the function.3 U$ x3 M8 c# s0 p ]4 S
*/
" y: O+ R% j! P4 H sync ();
* O7 p1 ?' ]& }1 r- O" h/ [8 X7 \ *addr = save;' z `& y6 q/ A& T' Q
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
0 Q# c8 J3 u9 w. d! O0 } addr = base + cnt;1 i3 m0 r e. l+ h# b
sync ();
2 G' o) @, M; s *addr = save[--i];5 H9 F0 R8 x6 ^4 {( B; I
}
$ [+ J; E& f3 h r% L return (0);
3 I, Y- D1 b& M( s1 z* y4 ~: N }
/ ]. l, [* x: ]% W$ b
% C( Y" s# ]) s. T. i' @$ } for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
: ]' b5 @) C; j4 ^* r( Z# A addr = base + cnt; /* pointer arith! */1 O T! L0 ?/ E1 Q h% R
val = *addr;" V) j9 D$ n) ]1 l/ k `
*addr = save[--i];
0 I; ~: e2 ]: { if (val != ~cnt) {$ h8 A5 k4 n: h' L% j! T
size = cnt * sizeof (long);
$ }! x- a$ B- |2 g /* Restore the original data before leaving the function.
0 y& f% X6 w6 w F0 \4 ?) |" U { */
* I" `3 g8 C5 G. z for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
9 W- } g: _0 \. R4 R addr = base + cnt;2 c/ A: p1 h2 R/ U3 P
*addr = save[--i];
* w+ F' y/ k* u8 K7 d; ] }9 n) e0 y6 W1 N: [5 m: y
return (size);
8 B2 V6 [% ~5 f5 O6 { B1 Y$ C }
0 R6 d& y3 {1 W) G }5 B% k4 P2 K; P
, b( T! @( R7 P
return (maxsize);1 {8 {8 |/ R* \/ L$ ]
}
& {' K% R/ P8 ~9 n W$ ^int dram_init(void)+ p2 u9 y; b; \& n
{
; c6 ^1 s. V, u% D% d /* dram_init must store complete ramsize in gd->ram_size */5 X4 f7 b1 _$ U
gd->ram_size = get_ram_size(
, g$ { X; E0 d6 p1 b6 T (void *)CONFIG_SYS_SDRAM_BASE,
, _" _5 F% o. y$ N: p; b" @ CONFIG_MAX_RAM_BANK_SIZE);6 v, O! s: [0 i+ K% j
return 0;& `/ ~! X1 `' ]( E" o
}/ y" j$ f" l: \; C2 Z0 y2 X
/ ?7 l9 Y/ |2 v8 D
; P" B9 U5 q+ b e& n4 X4 d; Y( M5 | d5 S" h8 d+ a- l( B
4 I, |' s9 U. D. _3 nFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
5 G' R f1 b6 w' V: p/ X, b4 x: M2 u' R I5 K
4 R( Z9 ~4 {1 x6 I6 ?8 [3 W+ v0 n( U7 A
|
|