嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit2 D! c7 H* v3 J9 E
核心板2:DDR2 256M Byte   NAND FLASH 8G bit
+ A& y+ ~  R8 u1 s* [" e这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?
: M# s# S$ M6 e& u5 f1 ]4 f- N' P" j( p9 M+ H
是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?
/ h  f( p8 ^, S
! x/ W% m) M5 B6 `, p0 p
作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
, ^8 P, A% h: J0 O  Y, b# p% k; W/*& d8 o, `' L" k3 q" }' o
* Check memory range for valid RAM. A simple memory test determines/ ~* y  C" P; ~' I, [
* the actually available RAM size between addresses `base' and8 w" G& w" v$ g) G
* `base + maxsize'.
- O! G( K+ o0 l: G*/( ~. v0 p+ f- c. _) x
long get_ram_size(long *base, long maxsize)% p( d6 a. a0 ?  j
{8 [8 y' g& K# S! l$ K! j/ A& x
        volatile long *addr;
7 R; X' b0 D% ?% Q        long           save[32];
5 {1 Q+ x5 w5 `2 L3 [% a1 N  ^        long           cnt;/ Z0 M1 K* S4 b5 L' X# Q
        long           val;
4 G  v6 o, Q7 R7 L1 E        long           size;
! s0 u4 H: C% @$ P! `" W5 M$ X        int            i = 0;5 {. p2 I1 G/ C* q
$ Y$ c3 l2 G9 i3 H4 V4 d1 x: u( Q, X- u3 k
        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
6 u; W) L' F; p6 y                addr = base + cnt;        /* pointer arith! */
& X  f; _0 w. x                sync ();
" N7 t- m4 l: D" }, H5 z                save[i++] = *addr;
6 u4 o% d/ t/ v( j7 Q                sync ();+ ]; D2 x& W* w% B9 w
                *addr = ~cnt;
$ x/ }6 B1 m: @& p! J        }
. b- s; T5 L$ S- i$ W* e; l$ Y6 O4 Q4 _4 R. g4 |7 J
        addr = base;; B2 r& t# `. h
        sync ();
) y7 [9 z" W$ U- _        save = *addr;- N! X2 ?! J  o
        sync ();
, M  e; b/ Z4 X, @7 l0 n        *addr = 0;
: \# f/ V% a7 b7 G5 P) c7 z7 X* L/ H2 ~9 q
        sync ();9 b$ ~/ B) Q2 _: I5 R$ D6 m* H
        if ((val = *addr) != 0) {& H( O1 Z5 E* E/ D  W% C
                /* Restore the original data before leaving the function.: m& l0 b, F. M: E$ [9 x; ^/ g
                 */
7 M2 y9 b3 P( s% j                sync ();+ G, ~* d$ u" Z- w4 {, N
                *addr = save;* Q+ G- a4 E/ g; t
                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {  F$ z: Q8 v8 O3 I! ]0 T* P
                        addr  = base + cnt;- S0 V, ^8 O9 h- v7 s) Z# P4 C
                        sync ();
3 X1 z4 p& ]9 y. d                        *addr = save[--i];
9 Z6 e  F1 N% h/ ^3 q! \" g                }& h/ k6 G( k0 E6 z8 s6 u
                return (0);
7 h+ _1 {  N$ b- n        }' N8 u# f9 M  d* P! c; B
: [9 g' G) g# k* _
        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {8 o/ E# x" b7 _6 a: [6 W
                addr = base + cnt;        /* pointer arith! */9 O3 f0 A+ F& ?) F
                val = *addr;
6 G, p' h' [. P& F; m1 l                *addr = save[--i];
% n& B: ]* S/ X8 w                if (val != ~cnt) {; C; K' ~9 j( Y1 n9 _# _0 }% u
                        size = cnt * sizeof (long);3 k  T* @, I+ ?' }: w8 V
                        /* Restore the original data before leaving the function.
0 f# W7 Y3 C) ?8 [; l/ q                         */
- e7 ?  c1 m3 M                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
: u8 o( S$ ^1 V1 h2 H$ `( Z                                addr  = base + cnt;1 t% W; t% C  l7 m& g
                                *addr = save[--i];, T& d4 [9 h2 Q7 C
                        }
; J4 g4 N7 n8 F                        return (size);
/ s' S; ?/ o  \! T                }! L* |* d# x* o; H
        }3 X1 V: r& i+ A0 m9 j% t

/ I$ b/ C' s8 T# o        return (maxsize);/ S5 g2 c4 w! }0 v: b$ T2 }
}
- b! G0 g) O* l5 r* u; K6 |int dram_init(void)  O' s$ f& y2 z1 I1 \! L) U
{& i6 g$ y+ |3 Y" R& _" x6 B
        /* dram_init must store complete ramsize in gd->ram_size */
1 c/ a2 I2 @" E" h" Z: h, b1 p- R        gd->ram_size = get_ram_size(
, ?* y* A( D. F9 K3 O8 d                        (void *)CONFIG_SYS_SDRAM_BASE,% l' M$ q) m3 b! h8 `
                        CONFIG_MAX_RAM_BANK_SIZE);6 Z2 c9 R- P2 G3 r
        return 0;0 P9 \; n) T7 N7 @+ t
}
6 V8 S  w0 [0 h1 p; ?0 B6 N- @+ E0 e0 X4 Q
$ Z+ a4 t8 V/ Q! K, z0 D7 M: l* K

3 {! X5 w/ f7 [; k$ e/ A
+ [$ |- _2 H" h1 ^FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
  b  U1 y3 N- m2 A
7 R9 `& B7 F! y% G. X( Z
2 F- @  a, ~+ l' [: @6 R" ~+ V

9 A2 A. W; Z4 ^: S" C, [# n




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