嵌入式开发者社区

标题: TL138 uboot是怎么区分配置两款核心板的 [打印本页]

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit/ C& w/ z' P: ^( c3 S- Y
核心板2:DDR2 256M Byte   NAND FLASH 8G bit
  C2 T0 G# a& ]* w3 T这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?
( l! f$ C% @* ~- D. X* ?" Y  Z
2 {( N  V6 j2 S; {0 ?# A  J& C是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?- z! c. C: T. {# x8 J8 k
$ a& y8 R' W/ O! Q- M

作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
+ i3 C# _3 M. W% g/*, P$ b( J) l/ e7 B$ \. m
* Check memory range for valid RAM. A simple memory test determines7 i: H. k% g' |- i+ Z% r
* the actually available RAM size between addresses `base' and$ k2 {& o2 a. @& E7 _2 @" X6 D. ]
* `base + maxsize'.8 [, ^. J% k" L1 |% {: R
*/- T7 ^$ M8 O7 H" }8 Z% T
long get_ram_size(long *base, long maxsize)
5 k( y( u! ?+ B- o8 C$ D) W8 _{- y9 z! K8 _: M$ v7 t6 R& y
        volatile long *addr;- l# Q- f. [3 y$ g
        long           save[32];# j; n( J) i6 P6 `6 M; m* z6 r
        long           cnt;: z% u; @4 }4 I& Y/ d
        long           val;6 K1 b' l2 h0 v2 ]/ G/ C
        long           size;
0 G* U) t8 ~! \6 }: N$ D        int            i = 0;; Q5 |3 j/ @$ C  _9 U/ o

( \! Z5 C- ]! r        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {/ |2 B: a+ S$ @: ~0 a4 M
                addr = base + cnt;        /* pointer arith! */
3 N3 z- G7 y! V0 b9 L* u5 p( \                sync ();
( L+ x! Y! x1 }% k) @                save[i++] = *addr;
7 ~$ b  Z# ~- h- B  E8 u0 l                sync ();  S) C6 [; p4 y* n+ b
                *addr = ~cnt;8 t  k7 c$ p, V8 i2 m* h
        }! ?0 w# b; Z9 Y2 b( v

  c9 h6 |  `) a% t/ x8 W$ `& K        addr = base;/ K+ N; d9 j  Z. w; }! g
        sync ();" c. _% \( Z6 {# ^8 w2 q
        save = *addr;
$ W# g8 q' u/ {: K0 x8 Y        sync ();
3 x9 O& Z  s& o( y% z        *addr = 0;
9 D: [2 r7 r' [! i2 g( D2 Z, k' K4 K# U$ f( ?" t! p' N' Y9 S
        sync ();; s8 [) o& p, M3 a3 U2 n5 U0 ~5 G
        if ((val = *addr) != 0) {: n2 p# J4 b3 Q; S4 z2 O6 q; e/ v5 n' i
                /* Restore the original data before leaving the function.
! l1 i2 o/ T/ {$ N0 j9 R( m                 */
# m* g9 N0 s, `! {+ J; B                sync ();
+ B' y- _7 V2 q6 Y# t                *addr = save;
7 S$ n  w5 P8 C! m$ k                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {" i; p* X9 s' O6 n8 k3 F
                        addr  = base + cnt;
: C; t. @$ p8 U! E* O1 w$ s                        sync ();
7 N  U9 Y* S/ [. m7 }" I% l                        *addr = save[--i];/ T, r4 E$ M8 G8 V( U1 X6 z
                }
% `' \3 R8 _; K/ K                return (0);) v, O4 }$ D5 Z1 B
        }
; \+ }8 E; B" }3 {3 F; Y1 K  \" q, ^& P  l; q
        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
" V% v1 g% s6 J2 }% p                addr = base + cnt;        /* pointer arith! */+ a( S& Z, Q7 T/ g: E. Z2 M. ~
                val = *addr;) C9 f9 z  Z7 {, z
                *addr = save[--i];2 {+ g+ U* B# I4 ^
                if (val != ~cnt) {, E. c# ?% y; f8 z3 z& j
                        size = cnt * sizeof (long);
: r! P9 J1 U0 F  `                        /* Restore the original data before leaving the function.
+ O1 ^+ Y# f( _+ z. x( [                         */! P; c! m0 M. i0 j
                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
, m! D5 C5 L, f, T% H) A                                addr  = base + cnt;
6 ]2 t  g6 ^2 \2 Q3 z1 f( f                                *addr = save[--i];; i7 o6 n& ]5 z9 p7 T
                        }
% d2 i9 _7 S# \/ E0 ^( K, Y& o                        return (size);. @, d1 i2 v- `
                }
8 X0 X( h& P+ [  t        }
  O2 ^8 M8 Y1 X4 P' [; V7 z1 q! D. F8 }, G. E
        return (maxsize);) ]; k- p  Z/ Y: J+ L
}
& G6 A2 G) o( F+ Q6 xint dram_init(void)
- E9 E* ~' }3 H) t( s" f{7 h* k8 k3 w0 z: x. A6 Y
        /* dram_init must store complete ramsize in gd->ram_size */6 }/ R; V% w, o/ K% e. w& x
        gd->ram_size = get_ram_size(
- e& Y' F7 B( k5 s, I% Y) i                        (void *)CONFIG_SYS_SDRAM_BASE,
3 u( C0 E( C: m8 p- A, U                        CONFIG_MAX_RAM_BANK_SIZE);
( [" m  y5 ?8 E9 H" D        return 0;# z1 \( \, J5 U2 C) Q) I
}
9 @6 j0 `0 ^, A
; H. [8 I  c  A3 W+ n! M# R% `9 R/ {# x
6 b, x, I: v2 J- A1 Z9 s, d

3 x5 Q* L% T& n9 XFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!4 ?9 D- l; i: A& V; G6 y
3 V1 F* i$ J1 t

, C# ]. Y- M! _/ x, W& P& l( {! ?

( Z/ H9 I9 T% z; ^. l! h, O/ a- L




欢迎光临 嵌入式开发者社区 (https://www.51ele.net/) Powered by Discuz! X3.4