|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
1 _2 e) X6 ?2 K0 K5 \/ _/*
; g: k8 Y5 C3 J6 t) J* Check memory range for valid RAM. A simple memory test determines. K1 k7 X4 d, b
* the actually available RAM size between addresses `base' and) Z/ `" S5 X5 ~! u4 }9 k6 ^# B
* `base + maxsize'." D; m7 h$ `# [8 q0 c6 f
*/- W+ U( _ E% j
long get_ram_size(long *base, long maxsize)
$ u. J- F% X, V- `3 G) M! E{
8 w/ M! F- n# f5 L* d volatile long *addr;' R2 s" O5 @: C
long save[32];
( L$ G5 f, ^8 n8 `0 x* _ long cnt;
- E" S# D6 f& U# U$ @ long val;
: \+ J3 N& ]/ W' g long size;% V/ q; O2 L: W5 k/ z- [
int i = 0;
3 [& H. Z6 R' H8 b" ~2 J% D7 [' U
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {1 n B2 W7 |" `
addr = base + cnt; /* pointer arith! */
2 K B* M" P8 [8 c* }% [( p I5 y# I; w sync ();
( p& W, K2 u, ` x# I9 _ save[i++] = *addr;
$ K- L$ r+ C/ ^ sync ();3 X) Y1 i5 G6 p
*addr = ~cnt;; W% [ D5 M0 q6 v7 o8 K7 w3 {
}/ T: \! V2 { a K% F# T
) a* j+ |6 g/ g% ]1 b
addr = base;
$ g, ~+ j, ]7 _ sync ();/ i2 F* E% _# @' X
save = *addr;1 l/ R: L$ _. D6 t, W
sync ();. M# x4 W, c/ f
*addr = 0;
! T9 V( q- l2 T# n( \$ ]$ L$ X& k: W! c" L1 j3 \: n$ w6 T1 b1 Y5 p
sync ();
2 g% Z2 H1 y% u; u9 y if ((val = *addr) != 0) {& Y3 _9 V" \0 x
/* Restore the original data before leaving the function.. [! a! V& |. e: i# S. K5 }# b
*/
9 {) x& Y/ T% B# `% e: c" n, Z sync ();+ ?! N( M* G' }- p/ e3 f0 d, @
*addr = save;
8 ?% Q; g7 w- E8 k0 o6 C, ^ for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
7 B' l P9 p8 V0 _ addr = base + cnt;
9 y- M4 U! G- X! n& G sync ();
+ d/ g4 `5 m5 b. G" d *addr = save[--i];' D' v# b. a3 @' M: A
}1 u) S z# e) {
return (0);
7 k: a' t& Q; Z2 G5 P) A" ^" S } H3 Y/ G2 w1 H
E Z3 C" `1 a
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {" q W' h, ~) a, g- B
addr = base + cnt; /* pointer arith! */5 F; {+ o% h) @' T. Y3 O+ M
val = *addr;
% N) d3 ^! {) n7 Y1 [& Q- ~ *addr = save[--i];2 Z: O1 x: @! B: _' n% D8 R: [
if (val != ~cnt) {9 P" V$ k+ _. Y0 i) c0 n
size = cnt * sizeof (long);
4 Y1 L& C. K" J8 D4 } N /* Restore the original data before leaving the function.3 u1 X, ?; Y7 x( Q
*/% U$ K+ R3 e. g3 _
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
" x" ]' H2 B4 G8 ~8 w. v addr = base + cnt;
f$ A+ N/ }8 l& w( y! K *addr = save[--i];+ O, q: g+ p% ?& h3 K) B, e1 w
}% Z4 p6 U# @+ F/ O
return (size);
+ K$ g- Z" k- ?' r/ A& P }
; g* d( S& X0 X& M1 m; w }
. h9 c2 Q0 W6 J% Y' W) i
+ l& Z* M! M5 c# k return (maxsize);
1 G/ t) b$ _1 _" t}) |: {# W" i( _4 Z+ [* u* L8 ]
int dram_init(void)) J- t) L6 X+ c5 U: Y* u
{! K) Y& w9 }7 C& e/ c
/* dram_init must store complete ramsize in gd->ram_size */* `1 B+ g5 M# g- v B. s' G& r
gd->ram_size = get_ram_size(; S7 Y- f- g2 N# M7 L
(void *)CONFIG_SYS_SDRAM_BASE,5 K- F* S( f$ [8 g1 j! o( I" n6 @" `5 L
CONFIG_MAX_RAM_BANK_SIZE);
& a' n" `8 A" | P1 Q) A4 [ return 0;
7 a. R+ f# u" w; Y4 R% ?}' z: ^2 h# _7 W. o5 Y) F" x* N$ D8 [
8 y( y. W* j ^; ?+ F
( ?8 S5 Z! z6 B" V( w% `
# G& n- V, K; K9 m% f B! }$ Y4 [; _0 O) ~
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!! Q C( p( r! n6 E9 j
, d# s2 E% m2 H$ D
! Y/ ^. Q4 @( ]: H% k! o
: a8 M' I4 t/ Q* R$ F g
|
|