|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
( D% l% A, w9 S0 G/*
6 q n8 x- M, J# ^# [' a; P F* Check memory range for valid RAM. A simple memory test determines
* B4 M5 n. n# b7 _! S& o* the actually available RAM size between addresses `base' and+ \ q% ]" N: T1 q8 {6 K' _
* `base + maxsize'.
4 \6 S8 y* n7 y+ f9 t) m$ f6 r; \8 X( v*/
* F* n+ j" j* e- J; X( g: Ylong get_ram_size(long *base, long maxsize)2 B6 R) V( j1 T; k7 r
{7 ^ Z+ _2 G/ Q. p
volatile long *addr;
6 a- W1 Z$ o9 ^6 b' ^ long save[32];# H4 w" w( A% L! p3 B
long cnt;1 R7 G9 R* T0 q, |+ {
long val; ^2 i' p" M6 W, \3 D$ E
long size;
9 z4 N8 @2 F7 y int i = 0;
8 q) y& |% U- d
: x0 P6 j" S& f for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {4 |4 |( B$ l. y- ~$ H7 X, m* x7 E% |/ ^
addr = base + cnt; /* pointer arith! */ d1 h# {$ c: |
sync ();* I7 M! F" A b) N+ A, N! I
save[i++] = *addr;
' u5 O2 e; N4 J3 }$ z sync ();
) ?; O2 |3 c3 H+ U$ n- q *addr = ~cnt;
+ S( f* f- K2 Z, S# o3 k }- f" ]: i1 J- \) v
# k- D1 }3 H' s addr = base;0 [" ?" r9 P* j+ [/ L: d
sync ();0 r: G8 d6 F' H1 A2 p
save = *addr;
) y2 b& Z( l+ ^; c' I sync ();
/ r/ \2 b Q5 q4 N! C *addr = 0;8 i3 A1 H; X8 M) I( H0 ~. E
2 w" G* I- }" M! `. V+ ^
sync ();
" r* n- D+ N- U! ?% V if ((val = *addr) != 0) {- P! m/ D7 q0 n& t0 |# h N
/* Restore the original data before leaving the function.
+ ]7 y; q! S8 u. \# q3 k+ z Q$ F: u */8 |3 h7 r8 l/ f: B$ s* w9 P
sync ();
. ~. P$ c6 a! }- \3 o! X% @7 j *addr = save;2 ]' {$ D) F8 |* b% T$ j6 w
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
% T+ v5 W8 U7 A" ~, B7 v+ W addr = base + cnt;
4 C: @8 @; g1 r/ ?; s& P sync ();
" _1 |! d' A3 C *addr = save[--i];8 M: w3 P1 o% H2 O2 a) p, L
}$ ~; f* y! ?7 n8 l' m' E2 W
return (0);6 d* q) B2 g5 Z) o# A
}
: t& R" K9 |8 T/ e! l. @% Q% H" {( g5 }) |% Y
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {# R7 K- }! S5 x. w% M: L
addr = base + cnt; /* pointer arith! */
6 }' Q: n# A5 d6 q val = *addr;
; h/ `# K. c/ r- ~ *addr = save[--i];
% C& ]" { I# V8 h( h3 f if (val != ~cnt) {' d& Q# J: [; D Q5 U
size = cnt * sizeof (long);
4 A+ D7 j, R5 ^7 f2 X4 h+ M D$ p /* Restore the original data before leaving the function.
# Z3 R2 {3 ~# F) l8 o */
& X H. J6 }2 q( Y0 R2 Y* s% m for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {- b- b$ ^& g* s, T0 d- U: a
addr = base + cnt;
9 U5 G* H: Y% h( d! P5 ~- ~( s *addr = save[--i];
, v5 k9 f2 }9 Z' J% F }
C( k8 x) Q8 L i [ return (size);
1 {2 q, j8 i6 T6 ]8 b }
$ D; X) o+ @' [5 O ^3 [8 g }
& o% T f; `, D( ]! g- H; Z. n2 }; U3 L8 c* q1 }
return (maxsize);$ g! A' G) ^% ^ w; a I
}
% x: {" t0 @+ V( e" O) u2 }' wint dram_init(void)
! K. {, d9 Y0 ?8 n1 V. i0 N+ Q{
: b" i# L2 `' ^6 o /* dram_init must store complete ramsize in gd->ram_size */
! M! J- z1 u1 U1 z4 Y gd->ram_size = get_ram_size(
0 j9 S0 E: E2 n4 s) P' N: ~" ? (void *)CONFIG_SYS_SDRAM_BASE,0 k4 q0 i$ {; V% ?' _
CONFIG_MAX_RAM_BANK_SIZE);
$ Y7 w! x) K% H9 v, M3 J return 0;
+ X1 c$ D5 W- w3 ~& c}7 R3 y6 A/ g5 D6 f4 }
# d1 F/ T' `0 @" {( `4 f
0 M, c( L- n3 T) ` g H
+ N9 C" r- d: Q8 G, S' |" r9 w5 E' j& z9 V+ _5 s n8 W
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!* j+ @4 B0 A8 Y% W2 w) ^2 e, Y$ |# j
% ^! D: w( W* h( `+ `) E% H$ C
8 m+ Z8 z4 N3 T9 B1 E' O
) ~1 |. h# x; a7 r ~, u |
|