|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:' X/ U% s; B- N1 ?
/*
% [2 U" q3 Y. I! ~9 l* Check memory range for valid RAM. A simple memory test determines6 G( I% ~- W1 Q- ^, O" a1 w
* the actually available RAM size between addresses `base' and7 i2 W% U( F. f* X& `+ l
* `base + maxsize'.4 R* _5 N9 E, A& |- H
*// j& p" [/ |" X( z, ] i2 _
long get_ram_size(long *base, long maxsize)
4 H8 q; {* j* e{: F: r9 K0 G8 m) g- C
volatile long *addr;
6 b& D ?$ W* B& s- N# Q long save[32];
6 r9 {1 L9 s- d. D long cnt;% A$ a1 d" l+ F: j8 V9 V
long val;
/ e& X6 J/ E0 Q! d long size;; z [! @% j' ~# [
int i = 0;
. d4 k9 b8 z8 N5 W+ I. [3 j* t( S& O4 U9 W0 q2 f F# v
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
+ \+ c! S. i" X* g5 i* A# h addr = base + cnt; /* pointer arith! */ q5 k1 N' J m
sync ();
. ]# l/ t% V& k save[i++] = *addr;% \4 x. ]" C( n+ t
sync ();1 d! H6 Y9 u+ T
*addr = ~cnt;( ~+ N# {+ T0 n* c. K
}! R6 O! s1 W! K+ V, J# F) T
; `0 L4 G) e) s( z- C) J' @2 d
addr = base;7 n/ C) x/ A% m0 L# H2 F# s4 J
sync ();: Z( D% f0 P: {0 f
save = *addr;
+ x% K; t4 [' y9 d" h1 B9 t: f sync ();; E- C3 T. j$ |
*addr = 0;3 L) l7 q5 Z5 [8 P
4 V2 t6 ~; b+ c j8 ^
sync ();
8 `$ t4 x6 C$ \/ f9 T7 ~' r. ? if ((val = *addr) != 0) {3 H4 q* U. ^1 J/ w: |
/* Restore the original data before leaving the function.
# d3 @0 C' I' n9 U8 v+ T */3 x1 v( g* r# l
sync ();
7 W, D8 q5 K+ G7 G F/ O/ N *addr = save;% [) q4 h2 T( p) D
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {# s' P- D% m" i7 k
addr = base + cnt;! {' M! T* f' e
sync ();
P8 P5 \$ N3 r) h, Z9 R. _ *addr = save[--i];! B% u8 I: |: X
}
& b K" s' }+ i return (0);4 @& W# T. \ u5 H
}
) C1 x* J# r. O2 w; P1 T- R# R
1 D. l) M1 C! r( C& r5 y1 N for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
) a$ B# L" }- T8 ] addr = base + cnt; /* pointer arith! */
6 g6 ~3 }, k: ]$ [0 Y) H val = *addr;
$ w- w# v/ I/ }8 \8 }6 {& s; S *addr = save[--i]; k# K) k& Z* g6 H0 Y" E7 V
if (val != ~cnt) {/ ~0 G" D6 O/ ?
size = cnt * sizeof (long);! m3 N( g8 T2 E3 D" }" D9 _
/* Restore the original data before leaving the function.$ p# U; z6 z2 L' N: ]
*/( G* w% E. F' l5 J
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {- l6 H6 ~9 m/ j2 I8 C) \
addr = base + cnt;
4 Y, a9 M. E9 w" p# u5 `) s *addr = save[--i];3 G) u8 N) Q3 O$ K
}
5 I# A$ q, u6 S return (size);
! @6 l0 Z- t* L8 I }
% x. h# Y) |/ g1 |' ?5 ` }3 s. V8 a0 h$ Y! i2 U* {
' B4 A# T* b- j9 r8 p+ j2 E# O, {
return (maxsize);
7 r$ l: ?0 Q- g) Q1 l}. ]6 `4 G+ [; _* E1 z
int dram_init(void)
- ?3 t3 W% n& }3 R0 j{% p5 D7 W9 {+ q8 N7 ^! ]
/* dram_init must store complete ramsize in gd->ram_size */" L% U% _, o( s
gd->ram_size = get_ram_size(. R6 l- z* D3 u9 }
(void *)CONFIG_SYS_SDRAM_BASE,
( U Q# C% L- A" b/ g4 z3 v CONFIG_MAX_RAM_BANK_SIZE);
$ D) V' q2 }3 K( q' D/ Q return 0;5 t% f" G1 u) O" c3 d5 M7 ]# n
}. ]( @/ }- f9 q* `3 r& ^% a4 }
7 n% h5 O4 e1 ~+ c. ]) D
+ z0 R1 @- N5 a F/ {/ X
3 }% s0 e) v! j9 m- C. ?
$ M6 v4 b: ]2 d/ ] p. s
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助! g* N( ^2 M K9 m k3 T) u/ t
- p- ^- Q8 V- Q" Y
( Z# J4 f' b# {6 N) z
; ?2 V+ z- v( m0 E" x2 s |
|