嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit
8 N& f  g8 @' U# d核心板2:DDR2 256M Byte   NAND FLASH 8G bit
" O; N, x* W( G$ Z8 G这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?
. ~  ^: H6 U& U+ S! H
- V& X9 s1 M, v# L是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?) J; N) |  U( L4 B' X+ \+ o* |
: g) G* A6 b3 W

作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
2 K( V3 S- @* \$ ?& ^! n6 F/*
# d; M; e% H# Y5 O) e* Check memory range for valid RAM. A simple memory test determines+ {0 o7 Z5 f; S9 N: ]
* the actually available RAM size between addresses `base' and8 T" |, t9 t9 \
* `base + maxsize'.
- |& C! f, b; [*/2 d8 g9 T: T: _' C
long get_ram_size(long *base, long maxsize)
* ?: x6 D, D' Y* {( R+ X7 ^{
4 D9 T3 T% g: w/ @- u        volatile long *addr;# i7 p# |* J0 c8 L7 d3 O
        long           save[32];
1 ^/ U5 G$ S# |3 [        long           cnt;0 N9 a4 i/ Y0 V
        long           val;0 C6 T6 a" m7 m! F) K
        long           size;
. e/ k  }0 N, T. ?        int            i = 0;( G3 O8 V1 q6 Q' D5 f
5 t; b% |. Q* T, I" M2 n
        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
4 Y, k& U# R$ v% D                addr = base + cnt;        /* pointer arith! */
* a$ I. K& D* G  L  \1 B9 d! V                sync ();
7 G# ?6 g4 }3 }                save[i++] = *addr;6 p+ A1 M, L& E* k
                sync ();0 S# V$ w6 D# _4 h8 T
                *addr = ~cnt;: [  }: j  [9 q1 R2 _
        }& K  a& ~+ o2 l# ]

% }6 r. z7 l5 X6 @        addr = base;4 }& Y8 ~/ R9 S. }) e5 S* M+ R3 n8 A
        sync ();
& g! y% u. S5 I5 |- A# |; h        save = *addr;
# I# o* D( k  A        sync ();+ O9 x) q0 ?. a! d2 F' d
        *addr = 0;6 b/ h1 ~; B$ @1 @% G# {0 ~6 ^
3 B8 f9 T# O2 ~) A( ]
        sync ();; s4 T1 [8 M$ N+ P5 w& n8 O
        if ((val = *addr) != 0) {, ~" o9 i. Q$ h1 @. o1 B
                /* Restore the original data before leaving the function.
+ n$ t4 e% T7 G- }+ t                 */$ y0 L4 C7 P8 s5 ^7 V' L
                sync ();
2 S1 B7 B( G; l; ]                *addr = save;; M5 q- m5 r  I: S
                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
0 S9 |: V$ G7 y& ^                        addr  = base + cnt;* R* o: ~* @2 a8 `  V- J/ z
                        sync ();5 \! E  u- ^# T4 \% J# C6 Q9 l& x
                        *addr = save[--i];
9 I4 E( t4 ^) s" `# u7 j                }
+ I# v0 f5 ^! Y: W' W                return (0);! c6 f# Y" G1 I  C0 F  j$ p
        }2 ?5 A' i. C% o2 x

6 I9 ?5 j) M7 U" H        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
5 F7 W8 d8 ^5 o. r/ ^3 I                addr = base + cnt;        /* pointer arith! */
9 L3 P( R( H5 u- i9 R( [1 h" j& h                val = *addr;1 k, ]5 q4 z. |) Q( C9 S- E
                *addr = save[--i];! e* E3 E3 L  U: k6 X# j5 |
                if (val != ~cnt) {. x/ m0 G  @8 Z! [
                        size = cnt * sizeof (long);0 M: ]+ R. z$ V3 S$ g
                        /* Restore the original data before leaving the function.* H7 P! \+ _* Z4 j
                         */# v5 i2 F8 f5 c
                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {0 T" _1 v5 W5 d3 \- P
                                addr  = base + cnt;- r! G# r, e% r9 H+ b
                                *addr = save[--i];
& W6 i; T- L; z6 O                        }
7 k, M; r+ N( B! b                        return (size);0 w$ ?- d% e5 b9 `! M; X' s
                }; U( q, X. W$ x$ E& t
        }8 k, m; `; O' d" `: ^* K

* S3 ~5 N* D2 h        return (maxsize);
% J2 m" F8 n5 a; F3 k( |}- \0 U/ \* p$ U, }8 F" ~; G: Q6 p* W
int dram_init(void)# b- a' C3 a& T+ m6 d$ }+ p
{
% m, a$ c+ `- @9 e7 U$ ~        /* dram_init must store complete ramsize in gd->ram_size */. i7 j1 b5 N/ f% Y) `
        gd->ram_size = get_ram_size(
9 O$ P. j: F3 t6 `                        (void *)CONFIG_SYS_SDRAM_BASE,
& P) h0 w. Q. C1 u$ r                        CONFIG_MAX_RAM_BANK_SIZE);! p$ O) b2 B3 F" Y  q
        return 0;) U3 i% C- K4 I$ X8 P
}( \+ L1 l  A( m; ^$ Z% T- p
# w% C9 \' l, L; o. r$ E$ U8 w
$ w) S$ D) G" g
+ H7 t0 d$ Q' M6 S& q) \
1 ?! Q+ c5 p5 P/ b
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!1 e. H( e6 ^  o

' R6 J* S: g' S5 ]' q: q
: D$ o6 ^  f( K8 f  U
4 H# s9 ]: A; I( J: G: O





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