嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit# a7 }' t& j, A7 H; z/ A
核心板2:DDR2 256M Byte   NAND FLASH 8G bit2 {" D  ~  c) L
这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?% G# ?3 K/ @9 c$ A

/ r- b7 ~$ O" y是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?9 i! E& P( C6 y3 A& P3 A2 T

& ?& q& R9 w. }7 {+ |5 k
作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
9 H: K) |$ N! a* n/*
' L: p0 h! T. x8 A, H; z! Z6 \; L/ j* Check memory range for valid RAM. A simple memory test determines
0 ^) {- N8 m- i* the actually available RAM size between addresses `base' and* Y9 F& |  ~% a) l9 l! {' c
* `base + maxsize'.. r  i+ N& x2 ~* U1 U& k
*/$ [8 u: n9 R# m: F+ W
long get_ram_size(long *base, long maxsize)0 `5 j2 J5 C2 c# z. ^  h% X
{
& t% j2 S& m! q+ G* h* U/ n! J        volatile long *addr;
5 g+ j! o* K( H$ j. T( ^+ P$ P        long           save[32];
4 x4 ~- `( c* Q$ `$ V        long           cnt;9 l- P- C( I0 X& s
        long           val;
8 W, x8 h/ |2 `( S- M  L. K        long           size;3 t/ P. i6 E! w0 X" O( P" ?/ F
        int            i = 0;) n' Z1 O3 M+ K& r* I6 f3 D' f
  O* a! X  ~( ?1 c4 |4 [" Y9 d6 O2 e
        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
- c# ?, u: h2 G: w                addr = base + cnt;        /* pointer arith! */0 ^& ^1 \; u- a+ p+ _3 M! k/ G+ p
                sync ();! w) c1 F& s0 v/ a  {7 Z3 ]
                save[i++] = *addr;
: P; y) w' Q" P! p* Q                sync ();7 [& z2 \0 w  _* j
                *addr = ~cnt;
' A& o: P- i, h  }        }
# g+ d# d& c/ Z2 R) k5 {& f; [# \. \4 D! R* ~
        addr = base;& Q! S  Z- {* ~" U& _
        sync ();" x/ S  T# B( d$ H% D2 H8 u
        save = *addr;) S4 ]$ P9 ~9 e0 {' w, O& s) X
        sync ();
1 _7 @; G3 R6 ~, S        *addr = 0;
  W6 g4 ^, m( o+ V0 {! W- M7 N
, r1 V5 n7 `6 G- ?* U1 q' a6 j        sync ();7 F3 h  a! t+ W7 q/ u5 z' h
        if ((val = *addr) != 0) {
. {1 O# n# ?; W$ p0 v                /* Restore the original data before leaving the function.3 g* `2 F% @9 z5 A' s
                 */
+ P0 ^$ z% F, W  w- k                sync ();
& u0 U4 z  q* b# i1 p                *addr = save;
8 @, \- x/ D1 }                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
! R" s& w( C" I+ Z5 ?                        addr  = base + cnt;# T! ?$ Y7 B4 Y& O
                        sync ();
3 ?/ W4 l- p" F* W2 C                        *addr = save[--i];9 k7 z4 ~  d! g9 x5 O. F, Y
                }
3 Z) }( c; C/ s$ B                return (0);
7 q! _1 p% y; U        }5 e7 y6 G, p& L2 j( c0 B+ {( W7 H

, p$ ?' F' _; P* N; J9 b- h* v        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
, G/ {5 w+ Y# P  R+ c3 d                addr = base + cnt;        /* pointer arith! */* o! a, Y" ^' Y  Y
                val = *addr;
; d( F- H& q) j' R: f" f) Z9 r                *addr = save[--i];
- }7 m# f" b) x. `                if (val != ~cnt) {4 N& m' n1 X& ?% q
                        size = cnt * sizeof (long);
- j, t8 f8 U- b- J) H                        /* Restore the original data before leaving the function.- ?4 u6 v  @+ X* C" e
                         */. T5 m, |# @4 f/ e# P( X7 [
                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {( ^  W: @* ~0 F+ m
                                addr  = base + cnt;
( O8 q' F* [! e' x- Q2 p                                *addr = save[--i];; ~" N8 M# X7 c9 m1 x
                        }1 W7 o9 S) Z4 J6 [* ^: T# v6 }, t
                        return (size);
) f1 \* t% a  l: R1 t9 {1 }! ]4 t                }$ A4 o6 E/ I, D/ r% i7 N- u
        }
: I3 Y- w- R  P* H
/ `& G9 `; K+ O7 `  B: Q+ B8 v& K        return (maxsize);
* t  l9 c, \" j  c$ W}% P/ E  |0 v0 j( ]) Q, i
int dram_init(void)
1 A5 z$ C& P  n+ T2 H8 ]{
' x" D1 Z, ^' s0 x% m8 }, u, }        /* dram_init must store complete ramsize in gd->ram_size */6 v: K& |! ~/ D1 ^. }
        gd->ram_size = get_ram_size(
9 e9 D/ `! N3 j" g$ k! S% u2 e                        (void *)CONFIG_SYS_SDRAM_BASE,
8 @# j6 v5 M0 P& a) E                        CONFIG_MAX_RAM_BANK_SIZE);3 H0 R! e5 k# p6 |$ k
        return 0;
' M& x' z7 I+ }}
8 R. [* A: t# A
" j; R( ]2 ~8 s5 g  W* p- t* D* L2 V2 |6 T; f! [3 I6 L

9 c  d7 }! `1 b! e
: F7 q3 v) T) r/ {" b1 m! {FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
3 V0 }9 t+ }7 x. J9 W8 z+ V) n# M+ i1 b/ W- O5 E& ?$ H/ S

% ^2 v0 ]7 B" a! b4 u: @0 x

9 |# f8 V. M) b2 i  \




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