嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit! I+ ~; B! E" E8 ~0 E
核心板2:DDR2 256M Byte   NAND FLASH 8G bit! L+ f! t2 J$ Z# N
这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?
! c3 A/ v  o1 O% d3 D7 k; J. U# f- H( [7 d$ M
是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?
9 L/ ], R; x. j- k) m; `3 U0 p! L* u
$ C" u7 ?) E9 U7 J1 l6 U
作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:; ]5 ]4 |9 a5 g8 H% S6 o
/*
$ R# `2 S+ s# M$ ]  P3 g* Check memory range for valid RAM. A simple memory test determines0 g# O1 G  }/ R# H, o0 v
* the actually available RAM size between addresses `base' and
2 W8 @* t) q6 N4 S0 |* `base + maxsize'.; R- l/ F+ |0 x" i, n7 w6 u9 y
*/
' l) I% W0 h# D. m9 B7 ]2 elong get_ram_size(long *base, long maxsize)
' v' ^- X  T- B) j) w9 Y{" @4 L$ o* Y  u8 I$ s6 {9 j
        volatile long *addr;9 y& j% d0 ~0 l- Z" {7 h
        long           save[32];. f6 a0 ?8 Q3 s7 C3 t
        long           cnt;
+ R5 t2 x7 @$ W/ _        long           val;
) k2 h' P, S. q, n. Q        long           size;
8 A& v5 j" z/ x3 K; H) {7 b3 b        int            i = 0;9 u, Q- r2 f& I4 v8 ]
+ G4 ^/ u! ~' @) ^  i! ]; u" P  J5 P
        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
: j$ |6 |" N. `' ^- Y                addr = base + cnt;        /* pointer arith! */
: z# Q* z* O1 x0 \2 ^* ]& }7 S6 n6 Z                sync ();# `2 Q  A) L$ W7 c
                save[i++] = *addr;
, g0 b3 U7 U+ F0 u& V8 w                sync ();0 W/ e8 p' c* X- A' p; c" x2 f% M/ U
                *addr = ~cnt;# a" U5 o; S! a2 e" Q
        }" g6 W' a, m1 b

( @8 W+ j( |$ t7 z0 }$ F, i        addr = base;0 R% J' l; L- F. r
        sync ();6 d5 O+ A* `0 Q( v( H% C4 {
        save = *addr;( k7 I7 W% M, w
        sync ();
+ V: L( t5 ?2 K6 K; X4 y, n0 V: Z        *addr = 0;
$ d; D9 m: J5 P# u0 {7 X) ~  }  z. W8 r/ r0 ^& _: A* B
        sync ();
& @+ p: c4 Y+ t. Q        if ((val = *addr) != 0) {" ^0 k. z- n9 s7 e# G3 |, F$ t
                /* Restore the original data before leaving the function.
; H& r7 r1 `/ _7 u6 U                 */6 ~6 P. }% q3 J: w. Z4 i
                sync ();
  B1 Y  h% d) ]5 H  o' K                *addr = save;
. `$ y* Y2 V; h6 A$ U' [                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
' }; u1 x1 y0 c# Y3 X2 g                        addr  = base + cnt;8 q$ t2 ?+ p- \8 q/ T: k
                        sync ();6 w" O6 \" W" t3 A" q5 |3 n; L
                        *addr = save[--i];1 b' ~& w6 n/ j
                }0 i' |, l% K$ z2 F8 O5 l$ u
                return (0);# \7 v; s- V/ Q) G4 V
        }
9 Q2 C, W; P) E) G! ^5 `
$ ^) F) h" g4 \) j3 e4 F        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
% d: ]& T( _* D" L, S                addr = base + cnt;        /* pointer arith! */
2 o: L/ M* b5 G' o- p$ R! b                val = *addr;
- c4 b9 s' C: u+ r! }5 g5 a  @( K* V                *addr = save[--i];. h( y6 C9 T( L$ L- ^9 t+ `1 V
                if (val != ~cnt) {
6 j/ E) K. I- Z( D# \& [3 S3 o; W                        size = cnt * sizeof (long);  O- `9 `% B& p: d- j  n
                        /* Restore the original data before leaving the function.8 d# s0 u: d- B# c; n/ D( r4 i' [
                         */3 `/ ^- t3 c  h# v
                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {+ ^0 @9 e5 A) q5 W8 j* O2 [
                                addr  = base + cnt;
- @9 T, i; w5 S/ S$ f                                *addr = save[--i];% z* \8 R3 n0 {" \/ \
                        }
" S7 n: s0 M) j. k) R& ~                        return (size);
. f% S0 x# e& M1 T. t' c                }' T3 W' A% N2 E" X7 H  v
        }
; d0 t0 D' }- Q# I+ L8 H* \
' H/ a! U6 Y9 j4 c% h" T6 _  `! w3 D        return (maxsize);2 P, Y* r* W8 D' @2 {6 p) }: ~
}
( T9 U0 w3 D: c4 {' Aint dram_init(void)% T  b  A4 M" T$ ]* p4 h: E, Q) t1 e
{- J$ |; c. g! K" J9 f
        /* dram_init must store complete ramsize in gd->ram_size */& O. F6 g+ m; L+ E8 H
        gd->ram_size = get_ram_size(
6 e( M, l6 R7 D  q* u! \9 X                        (void *)CONFIG_SYS_SDRAM_BASE,
+ N' ]3 R6 V% x% x! ~& @6 }                        CONFIG_MAX_RAM_BANK_SIZE);
8 W- ~# I0 r- i/ O# ^+ J! a$ \        return 0;5 O; D  b" B1 K% S7 T% I4 B
}
# u+ d$ \0 G3 ^) ?  `4 f$ L5 E3 }: ?' B5 L* s( `6 j  }  Y) {4 Z

& v" E7 m3 \/ ]/ u3 i$ x& k* `  ~4 Z7 c3 C- ?3 ]  b1 ]& r. `% w* l

2 j- F9 V( T+ {FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
4 v( K8 x+ i2 Y$ ]# \1 ?! A/ S& B0 Q; ]& ]4 f. L/ W% y0 n9 Q( Z# q6 @

2 m8 X# u+ E' ]6 w0 \; I

) V. B/ c5 j9 y- L; T# q




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