|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
# J" t9 I3 R U0 _# B4 S/*
" ^ O/ k# F, k1 R& y% m; A3 o* Check memory range for valid RAM. A simple memory test determines
: F( r# b ]; h8 ]5 N8 j* the actually available RAM size between addresses `base' and* L# a' q0 h$ r- j9 I8 T
* `base + maxsize'.( e. U4 U( ~) q9 ]4 t
*/
. z& t1 R) T' J. l* rlong get_ram_size(long *base, long maxsize)9 b4 I% K$ P$ `. R: l& s
{
5 e; d/ ^7 E# |! w volatile long *addr;
$ |( } l' T& X& H5 G long save[32];
. E! |# Y: s1 J, o1 i& l% ~$ y long cnt;
5 d3 U0 p! }# t6 ~. W/ D5 C long val;* A4 ]3 L3 \" Q, `! T+ {& W
long size;5 w) h8 i# H! O+ C( K' e q: {
int i = 0;! [* W U+ G) U7 o! w$ ~7 o
% @4 k, Q- Z( v4 y' [ ^ for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
( D& D0 q+ ], n5 F0 z+ M8 j addr = base + cnt; /* pointer arith! */
9 g* J$ z! }( ~: c6 A: D sync ();
( J5 L5 c# ^6 `6 F' E( I save[i++] = *addr;. j$ x1 E5 u p1 M
sync ();6 {8 J8 K% A" B; p. w: a
*addr = ~cnt;( |+ K9 ?4 F" l
}
# |) f! a' P. V3 H
1 |- A; k9 {( P: G6 q) N9 q addr = base;5 D& j6 ]- ~; k T
sync ();% Q' I8 R0 e/ n3 I1 P
save = *addr;
: J: w$ i6 z6 f6 S0 L: ] sync ();0 h5 F, a( F% K( B8 \; N) a
*addr = 0;" y7 W. n$ ]* L; u* j8 [
% T& A( u8 F9 V; x
sync ();2 |1 a9 d' g8 a/ U
if ((val = *addr) != 0) {5 U6 O; P" w/ I2 X% ]6 \
/* Restore the original data before leaving the function.# C5 L$ @, M3 [; C( @7 j! C4 b2 A
*/
% b% ^* b8 G- u8 c7 k7 e( x5 h: ] sync ();3 ]0 u* G' b1 D% J) L
*addr = save;
/ y, e6 p8 e. s4 R for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {: D8 Q' b9 ^& z1 D2 X+ t
addr = base + cnt;/ o* m' O5 M8 p: Y
sync ();$ K3 d+ ~9 W* l1 j% h
*addr = save[--i];
* K. \* g! _4 P' G7 F5 h }; l! o9 g5 h* T/ c2 g
return (0);% s; c% `$ s, @: ~. C# u
}
' J1 W. a$ [. f7 e& c6 I, H. u: u& k# n% A- h7 e
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {: Q' v- S4 N$ ]3 c" O
addr = base + cnt; /* pointer arith! */
' l1 _7 l' Y# V( Q( Z% } val = *addr;. K8 T( e, L9 _2 h3 f
*addr = save[--i];
/ j) T/ n2 ~$ r% y2 c) P& D( @ if (val != ~cnt) {
# ]! ]9 l x) o8 p* ] size = cnt * sizeof (long);% I8 j/ R# B7 J6 D+ T+ S
/* Restore the original data before leaving the function.
" H* v+ `2 U( @2 t* M* d */
3 Y( F0 F& [. s+ ]# S; A4 F for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+ l! G1 a5 A! B# [0 E% ~0 O8 Q) [ addr = base + cnt;
! C% x8 o1 R0 \- e, z9 S) _" ~ *addr = save[--i];
& c+ {! K' f. R8 C& E; h- f P }3 B% P: g1 r5 j2 U, u/ d; G2 O
return (size);+ [, { @5 N7 j4 |
}
! z8 h' @ _3 I' B4 T }3 V& G7 I' D* W+ _4 {% M
& f- e+ {) F& B: t; b& A: F# e( i
return (maxsize);2 r- I1 u5 ^- p7 A ]+ H" t' }
}9 [3 E& z+ V+ W; c7 ]
int dram_init(void)
% e* i4 @& w! m* U{
; g9 \% m7 R; l( i$ W /* dram_init must store complete ramsize in gd->ram_size */: M* f" `8 p, d/ T3 L' U
gd->ram_size = get_ram_size(
+ {5 ^6 I3 p" {" ^ (void *)CONFIG_SYS_SDRAM_BASE,; Z% L0 W0 ?7 E% n- b$ M- q- _
CONFIG_MAX_RAM_BANK_SIZE);) a6 S: E5 X/ l+ x$ Q# i
return 0;
. g0 M6 ~7 x: F! W o6 _}
$ u0 S9 i8 N! T3 P4 _! H/ B( D+ T- l m& W. d* i- m* {
F5 J8 A$ N' V! w; z3 O: w0 J2 E; V6 l6 f& x: j& |' S. P$ f
) T5 |8 ?; a; O2 ]6 W) [# K
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!) r6 O6 v8 o) y! \# x7 ~
- t& K" {0 `4 x$ L
$ N: \. s5 J5 n+ q/ r
* D) A: t4 a3 S, v; n2 y' P3 ~5 f1 L |
|