|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
% P4 a0 l) C) x$ S0 t5 B/*, V5 Q' _ i& C; Y
* Check memory range for valid RAM. A simple memory test determines
8 ?6 E C4 t _' }2 C2 C9 g& @* the actually available RAM size between addresses `base' and: D; p) b- T9 V/ v7 I2 K
* `base + maxsize'.- B4 a$ r$ P# P E0 j# i! g4 Z7 ~
*/
3 P1 m, z: ]) k1 h+ R% ]long get_ram_size(long *base, long maxsize)
7 J8 v( i$ w) D{! a# S5 T. h% u6 P
volatile long *addr;
3 D9 o' ~& N8 k8 M1 A' r long save[32];; C, Y+ h$ k9 d& w; E/ S" C3 p$ h
long cnt;
) l7 o! `, Z* }7 I0 D long val;3 G; X. I' ]8 i6 n% m
long size;* s9 h# ~3 U$ J9 k9 v8 x7 |
int i = 0;7 k$ D* o+ H, [ _4 O6 Q4 Y) f
O7 r! w: a1 E- V& Z7 y) M
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
- B' a4 p, o5 X# R% i) y: L* Q l2 q addr = base + cnt; /* pointer arith! */) y7 j, l, p$ S c( D
sync ();
6 [3 {* j/ `1 R% ?. L* z R- u5 ^ save[i++] = *addr;
9 d c2 p- |* d o sync ();
2 A2 ]) R2 W$ H8 N *addr = ~cnt;: @! u/ E- E9 m; Q+ F
}
6 N$ N" B5 y9 V E% ^8 ~. E! A: w+ L
addr = base;
* C" c7 L- M u, f& I sync ();
. t4 C W9 D$ Q4 y ^( s' U, V3 m2 A/ j save = *addr;' s( c5 R$ g7 b4 h& Y6 Q
sync ();" \! j! j: u/ q+ M# X
*addr = 0;
: |! A( {% E* t+ c! d: i8 R9 \! @7 R, `+ o( D* Y# ~
sync ();! [' b, \9 o8 m$ j
if ((val = *addr) != 0) {
* }$ L6 x3 Q2 p0 K* _- i- I /* Restore the original data before leaving the function.
7 ]: U9 P' ? z */$ P6 p( {* f; l0 O7 u! C: w5 O
sync ();! T4 W3 N4 }; l6 v
*addr = save;1 ]; L4 i( ]7 y- z9 A' N9 x
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {/ B( _8 [9 d* w; \ S+ J5 A
addr = base + cnt;
L( {" I9 n( d sync ();+ V; l/ T- P, E9 `' G) c' \
*addr = save[--i];! [3 d4 \7 c( @/ J
}; G# c: J3 W, o* J
return (0);
% y3 @ _ h5 T- c' _" L, r }! A. K1 i9 N+ E" ]
; E: h# S8 w- ?6 X4 t for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+ F4 y. X/ I5 ?! ?$ u addr = base + cnt; /* pointer arith! */
3 y! b$ ^* U+ n/ F: G val = *addr;
2 [+ r E% e6 |9 ^) c& k *addr = save[--i];
& }. Z7 Q) K/ ^! W' X if (val != ~cnt) {
6 Z) g" z$ \8 g% K5 ~! I9 Q- D size = cnt * sizeof (long);$ p/ o, m" q3 b# H4 _* `/ x
/* Restore the original data before leaving the function.
: a/ C! C: y& c! O5 q */
4 H0 ]% N9 a4 X9 V, `* b for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {2 b# z4 r$ I$ Q, W
addr = base + cnt;6 G: O' p( H5 W3 ~: Y7 K# `
*addr = save[--i];; ~- L2 L( ?1 F( |% i h; I$ `
}, _, w- b& \' ~; @2 ^$ ~6 ~+ k
return (size);
7 t# n/ ~) q# _9 Q. @1 _ }
9 d z a0 e3 Y/ R1 I4 S8 K }
7 Q. i# [+ k" u" s( w/ x% R& X" z; \' g
return (maxsize);/ v; a( w4 \/ G v6 x9 V
}) G& Q! O& j2 a4 k
int dram_init(void)% l' q- ?+ l4 \& y( I
{
/ i& C2 O, Z# H0 B& J /* dram_init must store complete ramsize in gd->ram_size */
& a2 ]0 c; Q/ g gd->ram_size = get_ram_size(
$ j! I" O, n, i (void *)CONFIG_SYS_SDRAM_BASE,' ?7 b+ [! y! P
CONFIG_MAX_RAM_BANK_SIZE);
" x6 ?% x. `, T* c/ H return 0;; j q5 ^# h" A* }8 a" h: T7 [ @
}0 P; w- u V0 H
4 T6 ]1 S/ }% s1 o6 S. v
[; ?3 p$ T" b% N2 u
M& L1 R# Z/ h; u/ C
" `8 j5 q( m3 l' c+ y) W0 PFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
5 y, n' W5 d- o ?& [& \$ X
, Z% m! w1 B) D, m) V: W f4 B9 z: S* u% y1 L8 }6 p% C' d
& o3 L1 m6 G' \( p
|
|