嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit
) U/ W* r& D, J( l核心板2:DDR2 256M Byte   NAND FLASH 8G bit3 T* h) j4 u; |) Z, O2 s6 C5 f3 e+ ^
这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?3 N  y( n3 o, e: I- w
7 |; b/ J$ F0 n0 W* {6 p9 m
是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?
( E& N* q& _" Z+ s& [6 V% f! m' j5 O& e

作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:/ p2 I; g6 d- t9 e4 @& q. k- J+ I
/*& r) p* h# i/ P% L/ Q2 m; Y* r
* Check memory range for valid RAM. A simple memory test determines
4 U* g2 a6 X* J0 S* the actually available RAM size between addresses `base' and
' D( k9 h8 C9 @9 W( H/ }* `base + maxsize'.* K5 U; l1 w& R* h9 Y& @2 }, v, `
*/( \/ ?3 D1 H. q% B
long get_ram_size(long *base, long maxsize)0 K: b' r- O; d: K( C- ]; T
{; o6 h* ?! u0 f4 I4 n! a
        volatile long *addr;
% T! N! Z# p4 O1 Y" M2 v" F7 ]        long           save[32];
9 H* {1 }" n5 c$ i        long           cnt;
5 p' I+ E5 \: w# f8 G' b+ N- c: z) p* V        long           val;7 ^. V; b# \; @! ?7 }/ Q/ u
        long           size;, x& h3 C) S( a
        int            i = 0;9 x# a5 Y* x# Q9 K7 y

. X# N, S/ Q0 B+ V4 R: y        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
4 Z8 U* q) c5 F                addr = base + cnt;        /* pointer arith! */0 |# t; P- T" @1 ]& K2 V
                sync ();
9 a4 _1 C* U. H$ A  B                save[i++] = *addr;
+ g. n5 p& ?; W; h$ B( W; W! w                sync ();7 Z) a# n. s+ z
                *addr = ~cnt;- u$ j  I9 ]" i/ S! i8 o6 L8 w
        }
( x7 z* h, K* ]* o$ n4 @/ Q: ~$ E. {; Z2 v  n; P( I7 f( g" ~
        addr = base;" u1 ^! d, k+ P+ L  m5 D
        sync ();# W& N; k  y" `$ f0 b" E/ s! ]
        save = *addr;! l2 g9 F7 s8 v, q/ \+ R; F1 Y4 L5 M
        sync ();
9 q: @9 n3 n: }* T3 p5 j- f* J        *addr = 0;, @' q6 W! ^& E3 @1 C2 d* W
! W/ v6 _9 A! ]! f1 P  Z
        sync ();
! j/ x( a5 r  F        if ((val = *addr) != 0) {/ J0 P& ?& d1 V' U
                /* Restore the original data before leaving the function.1 r2 S& I8 g3 `6 c
                 */
+ F# V5 B7 F& e. F! p: Z* u% u                sync ();
8 C# a2 d" b- j; c* R. c                *addr = save;) G% Y- o3 V2 ]* Q2 C
                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
* W/ _& k+ A3 C2 x. u5 [                        addr  = base + cnt;
7 H; a6 Z7 g0 f+ N                        sync ();  c) l: G5 L; x% S% I# U/ Y% Q3 U
                        *addr = save[--i];: A7 V7 I4 ^% s1 H3 Z/ n9 D5 o
                }
, T! e! Z2 d2 ?/ V) N  e  Z                return (0);
7 d7 r5 C7 ?8 m8 O1 q+ c  ?. z        }7 Y$ c# |) @$ @% O! u, }
1 u/ R3 e5 G2 \
        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
/ [* x8 P$ R$ B6 k. n/ l! h                addr = base + cnt;        /* pointer arith! */
) @$ S6 W3 D, P* W- a( _# V                val = *addr;
* M" ^! x- s8 P* u, ]$ [0 ^* f                *addr = save[--i];
+ `: f& J; |2 `4 E9 W                if (val != ~cnt) {
2 E, s- S) H6 _                        size = cnt * sizeof (long);
; |8 t- Z/ i  C                        /* Restore the original data before leaving the function.$ F. k1 v/ D! ^
                         */' c% K7 ^: S' f4 ]3 @/ [; T( ^
                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
4 y! D# G4 r# C; ]- S                                addr  = base + cnt;; y8 d" d. e8 e) G
                                *addr = save[--i];
. m! s7 Z9 R  O0 W                        }, I3 U1 S2 t( i1 R( s) a
                        return (size);
, Q3 Z, ^( {& r# f                }
  d/ j) y* ]& d        }
3 l* Y( |, S  _. C* f% N* u6 f4 p, W- r9 m+ A5 d
        return (maxsize);
% P$ l, h; X$ O) @* o}
0 b! Z, u3 ^. s6 |int dram_init(void)
$ A2 t# p4 B1 ^+ _  I{
9 L! |! M3 n# m1 k% g, h        /* dram_init must store complete ramsize in gd->ram_size */
# y" @0 f: s: K( H- `1 v; ^7 h        gd->ram_size = get_ram_size(1 Q6 q. u+ E6 D" c+ n; P# G
                        (void *)CONFIG_SYS_SDRAM_BASE,
' b  s3 y* a! Q" X4 J% {+ a" ~. W                        CONFIG_MAX_RAM_BANK_SIZE);8 E3 j# {6 U. s7 W: X% _% V
        return 0;1 `7 l: R/ U) d+ A
}; b% H$ j5 J3 c: e: s# t% V

* A* f2 ]2 w1 e# L$ r  J
4 o# i5 j) |, e/ h  a0 ?1 m0 l; u# z( O+ q4 f) {0 R. f- {& @7 U
0 y8 j+ I8 e1 ^$ B& v0 u: X
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!* f' s, T  P, h* e
1 M$ p* w" F. |4 D3 ]) M

# e$ f+ C# f! {6 k' _) ~
! b5 A/ e& k9 W4 g0 m6 F





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