|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:* c( U7 Y1 ~& ^7 p! `8 Y+ z
/*
C' \+ m H3 ?6 `; R* Check memory range for valid RAM. A simple memory test determines
" H9 o7 ?9 X, f' Z* the actually available RAM size between addresses `base' and \, s% g( H a; \ o+ c
* `base + maxsize'.
. N% @# w* ^/ z: C*/
/ {- ]. n" a* y vlong get_ram_size(long *base, long maxsize)
4 }9 ?" {3 r- T# X{
+ _& A2 i! \- N7 R4 R/ V volatile long *addr;
% \' ~3 ]5 f5 M, C! f* j long save[32];% J' D) T2 A& i& J K
long cnt;
! }* B" K- t& ?: ^, I0 N long val;2 s) W, y4 ^" z4 |" D' @
long size;
9 p) j# H) h; j& _9 S2 b int i = 0;
& }0 J7 ~# r4 V
" d0 s7 b5 L0 \0 m+ C1 h' p for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {& [* j$ G. b+ W9 h+ I4 J0 }
addr = base + cnt; /* pointer arith! */
4 h) W0 }2 B! O% r sync ();
9 F8 e4 w$ c0 r* f save[i++] = *addr;
5 d. d! N; D1 f$ b+ Q sync ();* s9 P4 |) l5 t0 ], C2 j2 G) Q; o* c
*addr = ~cnt;# Y" i) W! P2 m6 T
}2 d- W; F4 O% ^4 g1 y
0 c, y5 R5 W* p4 W/ y) w& a addr = base;; Z# y. |* ?* i+ V0 R: [$ ]
sync ();/ U( A$ M0 n" F1 @# H
save = *addr;8 d( u' V# K! t7 h# d* J1 {( d2 G
sync ();
2 l% u! ~5 O% @) L; L5 q8 ? *addr = 0;. C5 G/ a( E q' I* N& ]
5 g; j# }+ d7 G& c+ _0 a
sync ();
; ]% M% [% S% @% ` if ((val = *addr) != 0) {
8 S, A4 D+ \$ O- _ /* Restore the original data before leaving the function.
& C8 }9 j/ z1 ^3 g0 f */4 M8 E7 f! n3 ^! y. p
sync ();
; l: V- M) ?$ }. J6 o) }3 d3 X *addr = save;
# @/ f- {! N0 X: Q0 | for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {& j# {* Z3 }0 D
addr = base + cnt;
& Z' T9 n. ]3 f, p9 m' d' b3 s sync ();4 J* e9 i, i; R$ L& r
*addr = save[--i];; _: e2 v- N( P8 [4 a
}: k6 T6 v! W! B1 d" Q6 X
return (0);- D8 p! U/ @% F) e( V
}
3 [! t/ f" D( ]0 b" l4 M; a, s( W5 y }) P. m( u. ?; y
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {: |/ X0 o2 N" u/ S) e0 }: C+ E& j
addr = base + cnt; /* pointer arith! */
* p; w% O% R" V val = *addr;
: i& I) X0 j7 F% \ *addr = save[--i];* X/ c# C6 r" i2 I
if (val != ~cnt) { E; a9 v& a& ~$ j: t& S3 x
size = cnt * sizeof (long);6 h' F& \: H5 N2 K' k
/* Restore the original data before leaving the function.) z E. I% c( D- R, @7 c3 o |: Z
*/
6 i( A% B1 b3 T% K7 M3 w. U for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
8 X% s# f* _1 k7 ?$ x6 Z addr = base + cnt;0 s9 |* {9 q# w4 i7 r) s
*addr = save[--i];
2 m/ S. }/ e3 {; G }
$ t9 Z' I6 ?2 t- K$ R% Z$ \% Z( o return (size);# v# O. q% _& s2 a* S4 Z% }1 B% v9 E
}
) G( M* h; J C2 o1 b }0 T+ g) {3 o. M; r
2 @5 G, ~( ^6 {+ F return (maxsize);
+ t8 C2 ~% I: _2 n& a+ a}0 P, O' R0 [; k4 B- V! a& r
int dram_init(void)
9 D3 U) e3 Q' d. ^{- N5 e2 A% k4 _" K) f& a6 W
/* dram_init must store complete ramsize in gd->ram_size */
6 q; F5 C8 {: e3 b a7 ` gd->ram_size = get_ram_size(( C( ^' d- ^3 j# E* A& j' l6 Y
(void *)CONFIG_SYS_SDRAM_BASE,' d$ \1 d8 w" b( x+ X2 I
CONFIG_MAX_RAM_BANK_SIZE);5 s7 e& ?% s" G/ \
return 0;
, p" M9 L* K/ n- N! F% j}
: i$ N# y- h( W0 u, L6 _$ {) x9 u* S
& y6 L9 k/ ~2 b! m6 g! k- |7 `, p- `+ ?. l8 @
% C$ O, R9 k6 P6 q3 \: a
# O# g5 R. h$ R% ]FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!! a) w9 V% ?& d$ g8 U2 t" \" I) \
, S u+ b- a& v: l; f! @2 B0 a6 k0 V+ v2 t5 J* C% D( H
# i9 Q- v% H! ~7 r |
|