|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
, E1 a6 Q/ _6 T% K' b/*
/ E9 i W7 d4 {* Check memory range for valid RAM. A simple memory test determines
4 U% b6 n6 e3 v8 f* the actually available RAM size between addresses `base' and
% [, @# b" i% [2 C% S7 i* `base + maxsize'.% W! ?$ B! ]3 t5 t9 `: H7 k
*/2 V9 W3 Q' I I) c5 a
long get_ram_size(long *base, long maxsize)
. b F& F& c) N{1 e! P9 o# x# G4 H/ @
volatile long *addr;
8 I+ j) J4 u6 O1 O* N long save[32];
0 I" a* q; g9 c9 Y& P# c! f c long cnt;
2 S2 ^2 @5 H: X I long val;- E; i/ L$ L3 f- Q$ y* I
long size;
" K. e6 _! x( b# G int i = 0;& p* H" R9 k' M: `
4 I7 j" y# c9 |1 o. h1 K: A0 Z
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {* S) f5 W( P+ Y# L; m
addr = base + cnt; /* pointer arith! */, d* `8 `1 j- x, O7 g4 t: s; X
sync (); @) F F: ^" f( K& u8 P! n: o2 t* W
save[i++] = *addr;/ V2 R7 ^ A; @
sync ();
, @8 N. w P, \8 I) @ *addr = ~cnt;
( Z/ `: k; I7 w }# O$ A! l5 k$ t8 d3 U- a
- N' T% I$ y/ a* |5 R+ s1 f
addr = base;
9 d% |3 X" t' k sync ();
3 d( N3 J: S. u. K4 r% N1 o4 J save = *addr;
9 d; d! S' c/ F( b6 U; i5 @" y sync ();# k, a$ S- ~+ u# D+ k* d7 s% n
*addr = 0;+ |1 \ G( ]# }' j
, |4 y* z. A$ y# [
sync ();
1 a7 P# I% ^; G+ F. t3 } if ((val = *addr) != 0) {
+ U7 B+ O3 ~: `2 J$ L! `( P /* Restore the original data before leaving the function.& K% n8 x A0 |0 V
*/
9 F* U) u7 V+ d; q. u+ v% V+ z( \7 S sync ();
" f6 m4 e" \8 A1 K# ^7 { *addr = save;
T; |. u0 Q& y' T3 B T/ z for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {9 @, J. {& m5 Q# W2 W
addr = base + cnt;+ c! F" H _1 p, t( R
sync ();
. r b$ g9 B) w8 h *addr = save[--i];) u) U2 `3 V* h
}
2 k; V6 v' N' ]8 V+ c* \ return (0);
1 b7 H( g. D1 x6 [: Y9 G }
5 d2 {' g% j! F
3 r& B, p& `3 C for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {/ m5 X8 K, m: ^) a( c# o( k
addr = base + cnt; /* pointer arith! */' h# c, z/ {4 n% I2 t8 f0 n6 H
val = *addr;
2 g" {( h0 L1 l( u, e& o* I3 ] *addr = save[--i];0 a6 u0 ]2 Q" l7 P
if (val != ~cnt) {. _2 ~7 w) l! y
size = cnt * sizeof (long);* i, j0 G5 g, F; k1 ^
/* Restore the original data before leaving the function.. T- n) m$ V0 [& k4 w% E9 Q
*/
6 M' d1 D5 M @ |6 [ for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
: ]& ^9 E" o0 U: \( C" ]# h addr = base + cnt;
0 ?6 |2 r$ b% |$ M8 m" i7 i *addr = save[--i];. F& }* o7 r" a3 @/ P3 C R
}
$ A# z. }: G! h Z return (size);
. j8 F! S5 L+ M$ h* R1 v }
5 ^& V- k* X, M# V+ y! a7 P3 u }
8 s+ X8 Y6 }" s3 s x
8 {5 j% y6 N' Y& t return (maxsize);: d8 u7 ?+ ?" w2 m7 u, v7 {1 Q
}& K; ?7 t* P/ l8 c. b+ b. f
int dram_init(void)
1 s, M1 Y: I- T4 z4 O( a{
& y+ {/ y5 h/ V7 o* ^8 t9 D /* dram_init must store complete ramsize in gd->ram_size */
2 s, R0 \. R7 y2 Y7 e gd->ram_size = get_ram_size(4 H' d: [* J2 i1 |7 ~
(void *)CONFIG_SYS_SDRAM_BASE,
# c# X/ d- }/ L- R4 K2 w CONFIG_MAX_RAM_BANK_SIZE);- Q! ?$ u% k9 F/ s4 L
return 0;
+ |: G d& K0 O* N' ]}) f' n, e; s$ X3 y
6 Y& b" T% W/ L* d. m. }3 _
4 ?+ }: W: I8 M
9 f$ V5 V# m# E4 L2 x+ ~' C9 S& N! Q0 |; J* P* @
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!( d& ~$ P% Y7 r& u" X7 f; R
/ v" J* M2 Q# Z- p1 H: k
' ?" J% y; o, K
3 B, Z, J* P* m2 W+ G( ~% } |
|