|
|
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
) {& M: V% [! f1 @+ R/*
6 L5 p; e2 j/ o& ?5 v2 H% z( l% F* Check memory range for valid RAM. A simple memory test determines/ j' z/ W/ N( C1 W( l
* the actually available RAM size between addresses `base' and) P8 T( D2 D. y8 ^! ?7 \
* `base + maxsize'.3 B" y: x' _# w \1 ^
*/
: x9 e9 n6 r* P% z! ~ C* J7 {0 Nlong get_ram_size(long *base, long maxsize)+ x* J; p4 \$ l, c% p- a9 k
{4 v# N( g' @, Z( O! Z3 x
volatile long *addr;8 V4 @6 v* j, M2 v7 B
long save[32];
( m0 t* ^6 C K- ^3 B8 W long cnt;6 }1 |! U5 h0 c- j, D3 Q5 H( q
long val;/ ^2 m! d2 o2 ~
long size;
9 u: V4 S( y6 M+ S+ I e int i = 0;
2 n. b, j8 x5 o+ p) g" y/ l
2 C& H' j( N) ?; b for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {: J( `6 z2 i2 ?9 F
addr = base + cnt; /* pointer arith! */9 G' ~- X, i) {! w* a2 x i% p8 @$ r! q% u
sync ();
9 q. T0 Y! d5 C" K8 E3 `+ g save[i++] = *addr;8 m/ G# \) ?8 ?( G, Q
sync ();1 P* V9 Q& Z5 G: N: y! m/ d/ u
*addr = ~cnt;" @5 C9 M6 r* s: R
}
2 l' g1 S K' P8 f
7 C P" j2 o3 K# ^0 k4 m1 J$ P addr = base;, V, Y: a/ _7 ~, ]) f% k0 s
sync ();4 z% l& s& `7 V! f
save = *addr;* Q% s% T$ }1 {
sync ();
( p' F# O. h; n6 h$ E; ^0 ~) c *addr = 0;0 y u( T8 V& o( n3 [6 |* S+ \
5 a9 w& {% }" R% y- f
sync ();' t+ p: n! w8 e; ]: [9 e
if ((val = *addr) != 0) {
1 H, T; @ [' P /* Restore the original data before leaving the function. e& B7 U5 t/ s; `( h3 _
*/
' A9 N% L" _! V% d sync ();
9 \, k. C0 n) Q* U6 q/ v# @ *addr = save;
0 S% O( u7 c8 m for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
& d* C; H' |3 v addr = base + cnt;. w8 ?, [; c- H" [; C
sync ();+ C; E2 S- I; u W
*addr = save[--i];
/ Q: c0 ^7 s) X- F! Z9 S) {( q$ @ }3 U5 o; Y7 ~8 P
return (0);
5 P f1 v& `& e! r, i }
, k" A# _0 e4 U6 H( X3 [5 o2 S, R) @0 m4 t: f+ s; j
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
8 w) n. R2 j$ c I! d addr = base + cnt; /* pointer arith! */
E+ A7 {3 G& |& I8 s0 a2 h( Z val = *addr;" Z0 V4 H; i# v* j% Z
*addr = save[--i];
. f% d" P Y7 `& C8 W& C- s5 x' ? if (val != ~cnt) {
% M' V: \! u) J# c# { E size = cnt * sizeof (long);
! M7 {& R6 v; M9 m* x /* Restore the original data before leaving the function.9 G& b* a6 f. [: Z6 o
*/
% h) D3 w3 ?# ~) I, y8 ` for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {) `; ]# A1 b1 H0 Y! W% D! t
addr = base + cnt;
% o( H; _' y) r; `3 P *addr = save[--i];
' S- E- m% O" i }
; T6 _3 }0 n: M" {% Q/ { return (size);0 K4 R0 I/ X* Q/ y8 d
}
! W. v- ?. I! d6 N; X }. L2 m$ p( w1 h4 Y
' c9 }& p8 A# n8 i! f
return (maxsize);5 D* P, Q+ Y- w7 W) d+ ?
}
& {' w) y' g3 C; U6 yint dram_init(void)) V% f# l( n! w _
{
* G9 E1 z$ v J; S5 R /* dram_init must store complete ramsize in gd->ram_size */) L+ n( n9 B W$ ]" ~9 i6 o/ |; H
gd->ram_size = get_ram_size(
( _7 V r" K6 S7 k4 k. _ (void *)CONFIG_SYS_SDRAM_BASE,: l( H! L/ s' x4 T/ T/ A# X" E1 R- n9 j. f
CONFIG_MAX_RAM_BANK_SIZE);/ _* u1 n* e) A# \/ q0 @1 \
return 0;; A: L+ \; x" U
}3 w' s* D1 e9 Q( O8 s5 s0 h
: J: i5 _ r0 j% Z9 x
) ~3 T' G- r; R( H* T3 u, I1 {4 B [3 \# L! x
; \+ I$ @( L% x1 U9 t
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
0 @! S+ M$ I' U8 {3 _3 ?$ ?6 b4 u9 a' C4 \; n& a5 z6 w
/ _8 i# O) x h8 _8 X
. l L( M6 R7 ]& a: } |
|