嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit# \0 _  e# I- c8 x
核心板2:DDR2 256M Byte   NAND FLASH 8G bit0 C: O7 i0 C7 M7 U
这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?
  y8 o+ p; I  \8 o# I( h8 c3 t- T) \- l3 e: T' r! L/ H
是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?% o& }6 O2 T* J5 y
8 @% I/ c: A) W/ u$ N( G

作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:( `+ a/ `3 a# P# u5 O/ L
/*9 i: r! i7 `6 d' y/ R0 a8 |2 Y3 G
* Check memory range for valid RAM. A simple memory test determines3 k. b3 E- D! @) i& x6 p: V; j1 C
* the actually available RAM size between addresses `base' and9 C- ?, ]8 ^$ s9 |" Q
* `base + maxsize'.
; W& o1 O" Y% D& p+ J3 \3 F6 ]*/- E: P/ H0 L5 F2 S. v
long get_ram_size(long *base, long maxsize)
/ L. m/ l* T0 o# Q, U{) ?; G+ r3 t7 w5 U" x2 I7 i0 n
        volatile long *addr;4 K) {: `& X% S3 Q+ ?1 L* m
        long           save[32];5 {- S1 h% a* t; G7 P" X9 P- s6 v
        long           cnt;
) n1 @( N: [2 i) ~5 b! R        long           val;7 a& ^2 |, ~. x: o- m
        long           size;& ^3 `6 L  }( {2 c& m2 s5 |. v
        int            i = 0;
7 O, \0 _# S9 U6 S" g2 e
" s7 a1 a5 }/ I% x1 y5 S        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {0 L4 G/ m  ^  R+ A% E
                addr = base + cnt;        /* pointer arith! */
) s! E* Y7 T( n) Y" N  a4 F& m( c, ]                sync ();: X& K% N. G0 i
                save[i++] = *addr;# X3 a/ l6 K2 A2 _2 V1 C+ j7 O
                sync ();5 x, g9 [! O/ r
                *addr = ~cnt;: N( W6 W: g2 x6 M. n
        }9 I+ {1 g3 {/ {% S
& F; G1 ?3 b5 Y9 v8 T, P
        addr = base;1 y* Y, C* Q! w9 A+ K
        sync ();; e1 |4 c" s5 h
        save = *addr;5 l# L5 |1 A0 M2 ~8 b& x1 A
        sync ();: g1 h3 h5 B# O$ {% R5 A
        *addr = 0;
. q+ C% s1 ^* f2 Q- n  H
# ]: S" ~, g7 N- b. }        sync ();# B/ B+ ]/ \. p
        if ((val = *addr) != 0) {
6 n9 z. z3 a* |6 H: f1 p* K                /* Restore the original data before leaving the function.5 o6 h% A$ I. l- a
                 */, G5 t4 i. `- i; e/ E) q8 F
                sync ();
+ N% A) `& H5 B. g/ |3 u- r                *addr = save;
: ~; \/ l% {/ W( d9 r) }0 t& @                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {7 y$ o  s# Z, v: x  k- w! c" s
                        addr  = base + cnt;
. b1 M4 Y* b) |$ B* g                        sync ();
( o5 x) g" {+ I4 O2 E0 S0 V                        *addr = save[--i];
6 n& U$ Y8 ]: Z( V' H2 Y1 n                }
2 z7 H; }- s- B9 Y* H; @                return (0);
: H( }! I7 t6 b1 B        }2 \8 ]7 O& o+ Y$ P# T

/ m8 J5 G; X. s. }+ d        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {  q) E& P# }% H& @  ]2 A
                addr = base + cnt;        /* pointer arith! */8 y* ?/ Y& o! u% S5 Q" i8 W
                val = *addr;
+ a2 j8 D. |; j6 f9 q% Y# G                *addr = save[--i];9 f9 p) f, q6 \( q/ v& N" ?, N; y
                if (val != ~cnt) {
3 t0 w' R% {1 T, c; ?0 ~                        size = cnt * sizeof (long);- v0 T5 g2 x% j! X! Q
                        /* Restore the original data before leaving the function.; v" [5 c0 d* S9 L( u3 m( D4 S
                         */3 H) r' k  Y# T# \, F
                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
5 a* S' n; [2 Q& ~                                addr  = base + cnt;
$ ]7 g- e- N2 z& u+ i# R/ R                                *addr = save[--i];/ N# S& S" C. w+ W- f3 d6 x# W; K. P, M
                        }0 Y& Z: D6 d) r# t' e" V6 ~, ?
                        return (size);3 D( e) n/ m0 p
                }
  M- b. o8 ]/ b- u  P; Y& T0 J4 A) v3 n" R        }
7 X1 S: B6 t4 u- L8 @) X& q" r/ [) a
        return (maxsize);: `9 m, v( N1 y5 B
}: h& C7 o1 G: `1 l: C
int dram_init(void)
3 a& C+ I& f. H; l" B2 [/ P$ [3 f{: p" G) J/ L0 Y/ \, E: x
        /* dram_init must store complete ramsize in gd->ram_size */1 l6 V. t: ^0 ?4 e
        gd->ram_size = get_ram_size(" ~* d  T( y; ~
                        (void *)CONFIG_SYS_SDRAM_BASE,
' u  D/ L8 J3 R0 [- w                        CONFIG_MAX_RAM_BANK_SIZE);5 e! x1 Y0 d/ u3 P( q
        return 0;3 N8 O5 r  I7 g2 n
}7 e: Y7 V- p; c/ u0 m* j

6 X8 c9 v! H' I: t& j
; a! I% ]! |$ A5 J) u
' \$ J; [. Z5 Z0 h$ p( r6 m2 ]. [  j# z; f
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
9 ^( q, L4 G4 J4 |* p5 Y0 f+ w1 F  \5 e& j: ?
  V" B/ |# V2 A) M, Z' ?/ A7 ~. t

9 X+ e, R' j. H  Z1 M1 n




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