嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit% J8 t, s( o# H* t
核心板2:DDR2 256M Byte   NAND FLASH 8G bit
7 ^! F/ b' V/ P3 t这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?+ j/ V, A& S+ ]  f( A+ e

* u2 Y6 b; D$ g+ {( h是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?6 K9 P! {, V+ `8 n' F# _

  o, L5 e4 P! k$ j0 Z! J) e% r5 a- {1 O
作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
& y( g- p' a) U! y: }0 Z: J/*
* n, k; O0 Y- G' z' G* Check memory range for valid RAM. A simple memory test determines' v; ~4 b6 g& e! j$ D
* the actually available RAM size between addresses `base' and) ?4 ?. {. X& y; w4 p" A
* `base + maxsize'./ E# P# h7 R" Q( e9 w! l
*/' o& z) j3 N" f; x% v" S
long get_ram_size(long *base, long maxsize)
5 l7 m. S& h2 V{
& W6 M0 n  C% V5 `        volatile long *addr;
! z6 J+ G$ j% y7 m" s        long           save[32];0 z+ n7 `7 G' \" F% E# h, a
        long           cnt;
) n: ]. F- I) {& Z# d+ X1 L        long           val;- S) z9 L3 N& E- a& j% ?+ `
        long           size;* A! q6 _) q1 s3 s6 j# _% @3 Q! D
        int            i = 0;- G2 Q) W  I# X- `' J, \* L% z, {8 l

6 W: J2 h% [% n  f        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {$ A4 x' l8 s8 f: ?! Z  g
                addr = base + cnt;        /* pointer arith! */$ F6 L/ e: `! ?; {
                sync ();
+ S4 Y" H+ s5 P& b                save[i++] = *addr;; G6 }8 J: o! }) C7 u) b8 }* J
                sync ();
7 e. @! z' K1 v* |  m. K' i# e                *addr = ~cnt;
# ]) j% E+ X  p; g% i        }4 }. y; j& G* v' K1 Z  Q

" ?- ?4 l* [! `8 ^) h' K        addr = base;
. B3 p& b2 {7 t0 V) m7 e8 e1 J) V        sync ();
! T- M+ J) D2 ]6 ]* T; z        save = *addr;
( e2 p! g' @/ a- m2 u6 o        sync ();1 q, F; d0 {: }: c. E: y
        *addr = 0;
& N$ z6 ^% z  i% R; b$ y/ p4 B! i4 K. _  _/ |2 Y( W# \; u4 {4 c% [
        sync ();; j$ H2 V; R: e+ V1 o
        if ((val = *addr) != 0) {8 ^9 A* l9 C3 `) M( U! a. H' O
                /* Restore the original data before leaving the function.
: _; y  ]" \' A$ ?- j                 */
; D8 d# C! {5 `. T( T  W5 R; P+ T                sync ();. m" ~5 y2 Y( }  [, S
                *addr = save;
$ |6 M0 r  C) w                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
( T# s; `+ M% V' x, _' b$ n) ?                        addr  = base + cnt;1 `+ d2 p; J2 A$ @7 \5 e9 A
                        sync ();
' G# j& F2 m3 Q' K# E: h( S; i                        *addr = save[--i];
6 O0 h) R7 k. q2 d. G                }# w6 C: i2 i, m3 e! G/ Z
                return (0);+ M7 `! u( M6 N# {/ g
        }2 c, t- D" @: J6 D9 Z
5 S8 b- m% w0 Y; H2 F
        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {0 N- P  a$ @) z$ H1 c+ ^% J
                addr = base + cnt;        /* pointer arith! */
6 Z2 d: i) }7 D8 C% f                val = *addr;
" U+ Z0 w6 n( J6 x& t& ]                *addr = save[--i];
9 ]2 F5 |7 y+ Y4 i: \- G                if (val != ~cnt) {' D: [) n5 E5 [+ ^
                        size = cnt * sizeof (long);% e$ q: j( [& L! d1 Z& l
                        /* Restore the original data before leaving the function.
: \; E# L/ b& p. u) M0 b" v6 R                         */7 G- C! c- T  H6 r$ G: @2 r0 d  x* p2 d0 [
                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {( h/ M0 [0 [  T
                                addr  = base + cnt;
+ h9 }8 \  o# |                                *addr = save[--i];; R; e9 R3 ]* V& `
                        }
3 H7 P- r6 ?8 z8 j                        return (size);- c$ K: T: o$ l7 N" g6 E
                }
' E' [4 I6 ?/ d( ]; o% e/ L) C$ J        }
: O/ }7 C" t& V) N) P
- U& ~+ k  k" ~* C        return (maxsize);
) H- M% V+ W  t3 ~}
# {, I: t9 a' R: oint dram_init(void)
9 I4 i" d( E$ P2 h{$ }" q7 t' p- l$ I3 Q6 K( d
        /* dram_init must store complete ramsize in gd->ram_size */7 C( x  o1 w( ~* L$ K# F8 @, ?
        gd->ram_size = get_ram_size(. A( t3 A* z8 y! u' ~, N" j3 ]1 h
                        (void *)CONFIG_SYS_SDRAM_BASE,
5 o+ W& a. a% `" j8 y3 _                        CONFIG_MAX_RAM_BANK_SIZE);0 f8 A/ ~0 U% d& v% Y( K
        return 0;
% H; d) B2 @4 A/ R! u}# ]! m. [# Q3 |% k# I9 N: C6 e4 ^
% \# d! w7 {- P5 j, F# X
! ~9 h, t; E8 [& W6 g# ^

8 D; j2 L# e+ l# E* ]$ Y
* E& T1 ^0 |8 y0 XFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!0 g; c3 c- ~5 E) h* ?
0 B6 p( L+ w% k  B5 u- u

" _* j: }& h0 e$ q- Z5 M; j
  z) a+ g3 }1 R: ]; b1 \) g





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