嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit+ n( M+ A% u. x& c
核心板2:DDR2 256M Byte   NAND FLASH 8G bit
6 e: r, y" W4 [这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?( W2 u) M2 j" u6 }9 z$ Z5 I
5 U+ L& M9 B- t+ j& D+ r- H
是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?
! w9 f: l8 `1 ]) B9 p7 b" y+ M/ u" w  a5 C3 w6 b- _

作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:9 s" a# F8 g: N/ e( O
/*
( I" u! Q$ x$ X& `. O0 R3 g. I. X* Check memory range for valid RAM. A simple memory test determines9 ?  T- B; \+ |$ q" m5 G
* the actually available RAM size between addresses `base' and
% G3 Y/ }, L( ^( w. {) o. n* `base + maxsize'.. A7 P0 X2 o. |4 Z4 T) ~, P
*/
5 G) }5 J8 d1 F  i- V7 wlong get_ram_size(long *base, long maxsize)4 s$ B& k6 u" @' s# d
{8 W# T4 @& Z5 e7 D5 ~
        volatile long *addr;
) J, v5 G. d5 M        long           save[32];
" f; t8 m  J* v4 Q* w3 t1 ?6 r  G        long           cnt;- U# Q, f: O# K5 e1 x; E9 o
        long           val;
& Z6 |. f6 D5 j; j        long           size;: v  S$ K. e, S& C9 a  \7 W  A
        int            i = 0;5 N3 u( H9 G7 O5 \; n
' x% @( |4 s8 @
        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
, K# H& D" [' ~1 B: p9 E                addr = base + cnt;        /* pointer arith! */- Y4 I( K- f" H4 r6 f( e/ v' ]3 G
                sync ();, `4 j1 N' K; J7 j
                save[i++] = *addr;& Y& G3 B* x9 u# W
                sync ();/ o& u+ O2 ~4 E3 p! p
                *addr = ~cnt;
1 d4 Z( Z3 \* ]6 {' b. f        }
5 f8 G) v  o; I; }/ G6 }# |
4 d* V8 D) Z2 [9 l6 u        addr = base;
0 o+ M8 D& l5 U- B- X        sync ();: y* Y$ W; @2 I" W1 M  R7 S" r
        save = *addr;
- f3 k5 j- k+ n, @9 Q/ ]4 e! R8 `        sync ();2 q9 H& X/ b: z# }# P* R
        *addr = 0;  h8 t, d: K% X5 o2 D- q

) u+ E9 f; G+ _) V2 b        sync ();
% Q% k. |8 h; O3 t$ p9 x        if ((val = *addr) != 0) {/ l* E2 x  w5 f# @
                /* Restore the original data before leaving the function.- I  q- ]& z, s; j8 x. {
                 */8 ?' z! R  Z, Z- L0 A& f  z
                sync ();
1 ^+ i, R: q% r                *addr = save;
) n* {! J! |' R) b8 e1 L4 H                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {( T$ t2 u2 ~, Z+ R- U
                        addr  = base + cnt;
% S" G$ s! U6 V  _2 L, P. d                        sync ();- j* l4 @' E3 u, u. e+ R1 W7 p3 ~' @
                        *addr = save[--i];
1 i9 `3 e  v" R3 N5 O5 O                }
" |6 S( G; P6 y- G+ _4 z6 X$ K                return (0);6 C1 S" ]* x' }6 F# A
        }! d' c# r0 f! Q, C& U

  O+ _- I* J) M2 ~' v        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {4 |* N6 U, }) Z9 m: N3 `8 {/ P, g
                addr = base + cnt;        /* pointer arith! */: g; ]3 H8 ^' \! c7 v
                val = *addr;
7 c1 Z# _; {' }1 j                *addr = save[--i];
0 _4 _8 M  u9 \5 I# x% y# v                if (val != ~cnt) {8 C" m. B8 T1 p8 z
                        size = cnt * sizeof (long);' S0 W. V5 ~6 q" l* `: e
                        /* Restore the original data before leaving the function.0 ~) }$ O/ S4 j- T! m8 Z, w
                         */
8 a( [" p" c! n  \, @/ `                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {9 x1 D/ L0 h* H3 b9 g1 B* v
                                addr  = base + cnt;
* E' z0 e' V: K                                *addr = save[--i];7 d5 A5 f6 E1 \! S
                        }4 @) b/ W# K7 ?# D! v  T. S" n
                        return (size);% x1 o8 j8 G# x
                }
6 _6 Z0 i+ R$ n5 |8 K+ y' O        }
( v# [0 k! `/ c3 D  e" _& U9 k1 i9 ^  H0 [
        return (maxsize);) l% Y" M  S$ N
}+ T9 R, o% X+ j3 ?# f; B6 F
int dram_init(void)8 R9 i6 e# [" B8 V1 n$ G
{& G; \: H4 p" X% r6 t9 h
        /* dram_init must store complete ramsize in gd->ram_size */
6 t. T" ?  b, M  i- p: j4 k7 o        gd->ram_size = get_ram_size(
, a0 ^  b6 L& p$ m                        (void *)CONFIG_SYS_SDRAM_BASE,
: ]7 a$ L2 N$ F9 N6 P& n* y4 D                        CONFIG_MAX_RAM_BANK_SIZE);0 U. u+ s, w* Y) u
        return 0;; t; D- r$ n+ |! I1 R+ P- ?* O
}
7 U  [2 F  V  f# s, b: w5 I: B9 C! d+ i6 u  ~% R
. {& o$ I8 i  r
7 x+ [+ @- N9 `/ g7 f
( t3 B$ ~$ X2 W/ ~$ b3 g# E: J0 l  O
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!5 H( d6 Y/ q1 P% [! {

) b& n$ w( X6 d! U* o
, [- f4 F/ Q& w$ M6 k5 @  w' [  N

# _- C. e# t* J  h& h# @




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