嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit; g. d: f) g" r
核心板2:DDR2 256M Byte   NAND FLASH 8G bit) t& j$ L9 C2 ]' }  u3 V
这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?* T. w3 Q8 O1 l" I
# f# G8 O: i6 s; Y
是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?
  V6 G. _* D/ R& w# J
! h9 s# D- f+ x/ W
作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
* U, a* j% ~2 `' r$ T) X4 V/*
1 o# O" p1 v, ^' ]* Check memory range for valid RAM. A simple memory test determines
6 \& M( l5 ^0 Z* the actually available RAM size between addresses `base' and2 V+ h7 A: ?: k+ {- o, p% Q" i; a
* `base + maxsize'./ L8 \. H! v) k. w1 V# D- e! B
*/0 |% A  K, U2 h
long get_ram_size(long *base, long maxsize)
' r7 w1 z4 _$ D2 ~+ D" r{$ {+ ]7 K) U4 r5 C) Y
        volatile long *addr;
  e% V9 _' t5 Y4 H' k$ y: _        long           save[32];( g; F! ]9 J/ u8 a
        long           cnt;) G9 H2 {( @) \
        long           val;  A7 U3 R6 U% C$ ]7 O" M, G2 l) i
        long           size;' l0 P" U5 o. r$ ]
        int            i = 0;
8 c1 l+ p  ^1 }  ~4 ]( m1 h$ H# S; m2 G2 W3 v- V
        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {7 p" L6 |& O# n% `0 e8 r1 Y# d, z4 i
                addr = base + cnt;        /* pointer arith! */' ~. g+ p2 ]; J* n7 U- v. E
                sync ();
+ o) U/ \! ]) |) J! w2 N                save[i++] = *addr;  u3 h' u/ t9 s8 {4 h# @# H
                sync ();5 c& P# `# ?) T
                *addr = ~cnt;
, F7 o5 R. O1 d4 q% M! {" m        }0 d, h- h' V/ ]3 L' o

3 _% _: C3 W/ {0 G( `0 w        addr = base;
) x; d* m) ?8 `; d* k        sync ();+ v' ~+ P) c. |" C8 ]6 C. \
        save = *addr;& q: D) }9 K: x# R$ n
        sync ();' w$ z8 f$ J9 A* S' U$ X3 y1 e1 I/ s
        *addr = 0;
! O5 s' j7 l' _0 t& b. Y# \) e: {
& a( L% j. k& _+ G* O3 x" a        sync ();- r0 b9 O6 h2 n: G
        if ((val = *addr) != 0) {4 T' u3 y* i# @4 O$ D
                /* Restore the original data before leaving the function.
) Z9 l' c. s) W) Y                 */. M# ]) d  ^$ C" c( K7 X9 j
                sync ();4 h+ p9 I3 Y  N( O9 ?
                *addr = save;
0 N* k6 ]8 l3 `$ T0 g                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {  |( }4 o7 l1 p0 G& z1 s1 N
                        addr  = base + cnt;
) I1 Z  t1 P% s0 W                        sync ();/ Y+ L# g( {! i
                        *addr = save[--i];
6 @  Y+ u+ h2 Z( R! r1 S                }
- C; `& }% q+ j0 d+ M' r                return (0);& W+ o+ ?2 e2 V3 N( J4 F1 A4 a
        }
% p* _8 x4 q0 r- n# }5 q* K( M2 [" [" L/ j( p) B
        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {. b% Y9 v* a" M- @. e3 W
                addr = base + cnt;        /* pointer arith! */4 E6 v: F) o1 k& F& F
                val = *addr;
- _0 Q) U1 o! Y7 m0 Z                *addr = save[--i];
. C: F% i! r! U1 z1 ?6 V                if (val != ~cnt) {& C8 A1 O2 G  r. S! x
                        size = cnt * sizeof (long);
2 `5 A3 M  Z4 |1 \3 }                        /* Restore the original data before leaving the function.
: `, S3 G8 b9 D4 O# t                         */
3 b* O# H( ]- U( |7 R, p                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {- Z( D; g$ ]6 S3 m. h3 O
                                addr  = base + cnt;& f) k5 A( o* a! g! B3 P; w
                                *addr = save[--i];6 c! q& e0 l9 ]
                        }6 P+ f$ |' }9 N4 j, i
                        return (size);+ M. M1 T7 E$ }" D5 S
                }9 E/ t* |+ k: K* _, S
        }
- w( S" N! o( J; N' O6 |0 U/ B" i4 C/ E. K$ e3 V0 g% _
        return (maxsize);
# a6 t  W% O2 t" b7 j3 R}3 a0 i" x9 N  ]4 b2 s
int dram_init(void)1 J- R( [  F$ G+ y4 j! E8 T
{
7 G( D' y2 I5 T0 A4 O        /* dram_init must store complete ramsize in gd->ram_size */6 s% ]2 L+ ~" @  Y+ T) K
        gd->ram_size = get_ram_size(0 [+ Q5 @$ i/ `
                        (void *)CONFIG_SYS_SDRAM_BASE,& D7 b6 K5 ~4 d. z) A
                        CONFIG_MAX_RAM_BANK_SIZE);
+ k8 Q0 t( O* i        return 0;
4 B; y7 s( l' H7 L}3 E" i' N& j/ e2 }5 l, C
3 P4 }/ o! |' G- ]6 x6 b6 S$ Y
$ |- B0 _4 q/ Y/ C* ^$ V8 A
* C1 a" g2 A- ]
! ]' ^  ?+ k. l: j6 j) g" Z
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!- k% _0 j4 r8 L2 D

2 B  L& j8 Y8 e9 w& V7 [8 }5 C9 N) V/ A$ S/ {0 a
9 `! p: u6 @& m





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