嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit
1 I3 @$ l. L" }. ]核心板2:DDR2 256M Byte   NAND FLASH 8G bit: m3 i  R& F, D# ?9 L# p2 e- B7 w& \
这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?6 M0 D" E0 C" m2 e9 M& t

1 `: F' G- A6 s. a4 L是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?. H: a* x- W* |
6 t8 E% o) E1 O9 r6 l

作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
/ ]# g9 j9 b1 \5 `. J& C/*
1 \+ U3 n* Z! P, C% d: R9 J0 v( ^* Check memory range for valid RAM. A simple memory test determines
/ Z& A  \* V/ \& s* ]. g$ ~* the actually available RAM size between addresses `base' and' d$ b3 O& U/ h6 F* N
* `base + maxsize'.& `8 x3 L6 T, w. ]
*/" v) }( `! U. `9 j. j7 h
long get_ram_size(long *base, long maxsize)! Z8 m5 d* i! H* R( a& B
{; E7 g% i- P8 L6 H% @
        volatile long *addr;
# c; U# h% k& {, V* D- A" \        long           save[32];
9 L. {, C: p3 ~. B& U' K5 K8 U% {- F' z        long           cnt;8 u( u  y& l8 w
        long           val;5 ?; O" K2 k; }' O" T
        long           size;+ _1 k4 I9 k# O) L8 c
        int            i = 0;2 G' [+ z# o, p3 w% y) y- ?0 T

2 R; {9 T* \; [        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {. n7 m1 L3 c5 \. y- i- J" q6 s
                addr = base + cnt;        /* pointer arith! */
3 X3 e+ ?8 V* s2 g1 A                sync ();, u3 S( x. Q- i
                save[i++] = *addr;
2 Q- ^$ B- m; o                sync ();* f$ F& y3 r: U, ?. `& i( F0 u7 J
                *addr = ~cnt;5 i, Y& \% Z1 c$ j1 F% P% O
        }
, M/ E) U$ E( i! i. w& B2 x- D. W( Y+ L3 f4 \
        addr = base;
$ ?5 n* p7 F5 |        sync ();
4 O9 u. D$ j$ X% A) Z8 `        save = *addr;6 [9 r! q; h) V6 ^
        sync ();
0 H/ M1 [* @- V$ r* {. v        *addr = 0;
# L9 ?* V* w' S' A9 ~* G9 m; [# r% j& S5 [( L. o  g
        sync ();' r: H# ~, Z- G9 ~7 R6 K
        if ((val = *addr) != 0) {/ }5 k" _1 X  |* {' V6 e
                /* Restore the original data before leaving the function.
  @6 N$ l' y7 P* @- S! O                 */# y2 }/ B( Y: M( Z3 I( I
                sync ();( X( Q4 n1 q2 H* s
                *addr = save;
$ Y/ ^5 p. C; ]8 }1 {0 U                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
* E' c3 W% M2 o# }8 b  t7 R                        addr  = base + cnt;# K, |. f; F% e6 F7 I1 B+ c
                        sync ();
4 |. A/ ~# k1 @8 e2 Z                        *addr = save[--i];
/ D9 c8 G, o7 W; o* |                }
5 @" H9 U  s/ I% x8 k3 j                return (0);1 c' [! L' @5 O5 s; Z$ Z4 _
        }. i4 C  H- c1 n1 `, e9 P  z

+ ?3 K6 t5 ], O4 O% Y; I- ]+ s        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {' b5 A$ D" i" y. h. a, Q
                addr = base + cnt;        /* pointer arith! */
' k$ W' Y, n5 m4 f* k) R# X  s                val = *addr;. J8 J/ M/ ]6 A/ @) a/ H5 k. w
                *addr = save[--i];
, m: O; F$ Z* R' H                if (val != ~cnt) {
+ y5 {2 v1 N! y; k                        size = cnt * sizeof (long);1 k; z0 k4 K; q. j# l
                        /* Restore the original data before leaving the function./ R5 K( X& k3 K' v
                         */0 r3 l/ n8 {  v3 _6 S) ^; {1 Q
                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
$ O! m: s% L& D' e/ @$ c5 a5 ?                                addr  = base + cnt;4 [4 u2 y3 L. R4 a
                                *addr = save[--i];$ l' D1 Z; ~/ |- T0 E1 E5 w
                        }  K, s2 F& K) `% k: z7 P7 L, {+ N4 D
                        return (size);
5 J+ H3 R7 o- R* I  l. ]9 K$ b/ o                }
( d4 }& w1 e6 t3 ?, C        }1 K& L" m; `5 S

" K( W, ~# ^; _* _        return (maxsize);* G  F8 H! A: T
}
' }3 e0 z2 b# D( {int dram_init(void)
. ?4 W& ]" n% t, C$ |{8 j" k) K6 {# B7 ~+ W2 d
        /* dram_init must store complete ramsize in gd->ram_size */
8 {' o) w% a  {8 }: M% f: ]; \$ T        gd->ram_size = get_ram_size(
! d: F3 [3 v8 V& r- e) c                        (void *)CONFIG_SYS_SDRAM_BASE,; Y2 @% y. I; G4 `, g. I5 h; u2 J7 F: e7 C
                        CONFIG_MAX_RAM_BANK_SIZE);
) Q8 ^; ?  _/ W: k6 Y' W9 [/ W        return 0;
3 Z& N/ ^4 {# c  T; u}
% k4 u' ]5 r, W! z- p" j& b) d% U7 j! n% ^& i6 Y
) s8 h3 C/ ^% D2 v0 |; i( ^

* R3 H# Z5 U' u' c6 Z  S4 b* g" g1 m3 w* ~$ l% X
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
- V+ `4 p9 K. s  _" I5 L+ d0 `* B$ L4 S
! b7 V# x7 ^* h
) ?8 }3 I( ^" ~





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