嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit- j; m. M2 y: D0 }" v4 i
核心板2:DDR2 256M Byte   NAND FLASH 8G bit
8 \! p2 K* U7 ?% h这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?
( e3 _' H7 M! S7 t& V
- ~  [- {' ]% q  I- y. E3 X是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?7 F/ V/ ~2 h) u

& r$ i0 H) R1 \1 A
作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
' r' J2 q* a4 x/ Q  \8 `/*
" t8 s, l/ g7 z# s* Check memory range for valid RAM. A simple memory test determines
& n6 Q' I6 V! B* the actually available RAM size between addresses `base' and0 a# h; W+ F! W- T: n
* `base + maxsize'.. {% r; c4 ]8 F- J) L
*/+ q* X/ Q6 q' Y9 P7 a$ H9 S
long get_ram_size(long *base, long maxsize)6 y& N$ G* r. l4 C& c
{. o) |0 u- P9 \& {9 k
        volatile long *addr;
  y+ l* |8 I* r3 Y/ C        long           save[32];3 d/ _$ t/ r8 z# L% Z2 u  ]& u
        long           cnt;
; E- V, p: T3 B% |. C        long           val;
# q1 ?7 {8 W' D* S& }& {        long           size;/ N- x( T9 p0 D* B0 q' [
        int            i = 0;
2 Z1 u: g) ^# H& i/ {( D  Z- q
# \. @- |* A$ ?! n' J        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
* F3 _; P2 w$ h- D5 j- n                addr = base + cnt;        /* pointer arith! */# W. D% V6 |) j3 j) @! D( z
                sync ();$ v- s% q& h' O4 }5 K
                save[i++] = *addr;
% p1 U& Z2 f% }                sync ();
" v5 W# W: u5 L! E$ L                *addr = ~cnt;0 m  }5 j# ]) `) n# K
        }; D$ R9 L* ~: r5 C3 ?! d6 f$ e$ y' P- N

0 X0 U  }) D4 @9 z        addr = base;% R7 E" L5 ^! C/ b$ }2 _& x; F* `7 z
        sync ();  r6 f; r9 d7 E: M% A
        save = *addr;# a1 l4 T+ H! ?6 V  w7 O" Z
        sync ();
" N' F" J8 D' H5 I  I: {/ F        *addr = 0;3 e2 N5 }5 F0 G; U1 k

* E7 b3 z, Y. b, Y        sync ();+ ?8 n% S' \" V
        if ((val = *addr) != 0) {# x1 U3 g+ N+ n; {: @
                /* Restore the original data before leaving the function.
/ P% _  Q) @- I( O: A                 */( g$ |2 N" E3 z+ i2 P8 w' M
                sync ();8 m, @6 y5 [; ~  ~. m1 s7 f
                *addr = save;
: F8 M# W; f" s, K1 r0 j3 E                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
& y. k+ c# ?$ s0 }0 `                        addr  = base + cnt;8 e' g0 ^6 C0 V$ i$ e8 P
                        sync ();/ J; w2 y% i+ r; D# ~$ v/ ^
                        *addr = save[--i];
; B4 q; `  s& s4 A                }
, S3 U9 b/ ]; D                return (0);
1 V- [" Q0 c) n, k1 R        }
$ b0 m/ L( _3 Z0 l' R" e. v' B
/ r/ b  P7 F' k: c  x& b# U        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {6 d3 T  q. Q& ]% q$ g
                addr = base + cnt;        /* pointer arith! */
/ _) `/ V% J; T, f                val = *addr;
! t# W" f! U1 I( R                *addr = save[--i];
/ {8 @9 z* C* C8 d                if (val != ~cnt) {) V; s# V9 T: x2 d
                        size = cnt * sizeof (long);6 X" w" [. k# U; ^" P0 L
                        /* Restore the original data before leaving the function.% j2 w# A0 z, |4 t2 Y
                         */
3 L/ \# V/ W8 F% b- P  ^. [                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {1 X6 a, L$ k* w& A+ I" \0 U4 M9 C% C
                                addr  = base + cnt;
3 S# f5 ], M+ t                                *addr = save[--i];
/ Y" t4 y' z3 T, ]                        }. _; b) d5 Z* q$ [, v4 \8 S
                        return (size);
% ]+ B. P  U- P2 a) ~. }* ?                }
1 Z4 H& U. J3 W4 `6 S! a        }3 t  l' x0 U' L  w5 N
) F# ~$ g, ^4 ^6 w6 \# B* j
        return (maxsize);
/ G( x2 Q3 i% i# z# b. S! o}4 F' q2 x* N$ ?: n
int dram_init(void)
4 M, N% |5 T. e0 i% ?$ [& G{
0 p. j4 \6 a7 Z/ j        /* dram_init must store complete ramsize in gd->ram_size */
' Y. U2 h* ^9 f' J8 C, F! z! ~        gd->ram_size = get_ram_size(
" q  i5 I# ~3 x$ D                        (void *)CONFIG_SYS_SDRAM_BASE,
  p8 f" t4 ?% r: ?' ]                        CONFIG_MAX_RAM_BANK_SIZE);4 _+ ?& V. m% s. x
        return 0;
* a( G' T: k9 _% ~$ p( I. N}7 K- T' X/ i# \( {$ t2 ~2 Y
' \: S; n( Q2 O7 U# s  j1 Z6 d

" i( j& ]0 @  w* {
' ]0 R# O  K8 E
& e4 t2 O+ ?1 v: |6 g, c/ n) oFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
/ P3 u9 S- }9 c' E, J7 D$ x4 g9 p

; }% _% D8 w& U% ]

# l7 \6 R; I1 e) M




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