嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit
* H  c: D. p: o4 g1 \核心板2:DDR2 256M Byte   NAND FLASH 8G bit
, k+ Z* h8 A! W" |  ]( O! g这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?) X# R3 }* `5 h0 t2 ^- e$ a  D
9 Q; J  Z7 Z0 I5 a# C* h! A
是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?
0 [, d' {  o& L# A0 x9 I3 M0 N. b2 B
" g0 I  c4 t0 x. i  @# T
作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:* T, |7 ~- g- S! s& f0 b( X
/*
( y# D: c: H# F2 y, }* Check memory range for valid RAM. A simple memory test determines
9 S% G8 x; ~4 X/ B, k* the actually available RAM size between addresses `base' and) R9 h- |  ]& i4 n* L( l
* `base + maxsize'., _3 P  v; m* n8 J+ _/ Q2 i& V  @
*/( L& Y& \( r/ s2 h. G
long get_ram_size(long *base, long maxsize)
& {1 A1 L4 S( T0 f9 i! m* ]{5 m. J! o8 B$ x; w
        volatile long *addr;
( y7 G) U$ X4 [        long           save[32];( M& G- g4 R0 e. y+ Y
        long           cnt;
" j9 S' U' o) v        long           val;# |' h7 g' q4 V9 U! t* z- _0 c
        long           size;" G( Z1 J" L/ l, e, _
        int            i = 0;5 b7 r8 `: {: o; b* |! O* |

( r- d: }2 V# T1 y" R6 o        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {! p; b4 S6 q  [
                addr = base + cnt;        /* pointer arith! */
! C+ }/ B: N$ K, ~, H' v# z                sync ();
) @* O0 }( U; J: u                save[i++] = *addr;
1 f( h/ p; B% V" V7 {. W9 k                sync ();1 B& s1 i. B+ N. I; P3 }
                *addr = ~cnt;) O9 \1 y, t- u! ~) n/ {
        }
# Z$ d3 p; N& v' ~4 x/ \" k8 e/ b9 c4 ~) v) z+ K( t; ]% \1 f6 r1 z. `
        addr = base;: u/ ^, h& X+ J# Q
        sync ();  V% H4 ^# s3 b1 h: O( \
        save = *addr;3 V, p# ^) k5 J9 C) T1 C
        sync ();7 ~4 J4 \/ s6 Q
        *addr = 0;
  v* P: D. X  F8 T/ ?: A+ o$ }( _" m8 c# r5 q% M
        sync ();
; J5 Z* d2 l  @% G( z9 `- e6 |+ K& T        if ((val = *addr) != 0) {. c" r  t4 a* b" E2 h. n
                /* Restore the original data before leaving the function.( ^" t; A& j/ K% W$ M7 `
                 */& @6 g/ k' l# u! Y
                sync ();
& P7 p; u% V' w$ g( f6 E3 L0 c                *addr = save;) p/ C0 w# T9 p( B8 t: P& U$ m
                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {" A$ o& I( ?" @' P& L
                        addr  = base + cnt;
2 Y3 S3 @) w4 H) M: y                        sync ();
( |" u) n, w; N- g0 z! \" l                        *addr = save[--i];- d3 M  J# i( l$ x$ z
                }
/ d! Z9 u" l. @! l- {% k                return (0);
. o7 H1 u" I* R* T% a        }
) o1 H3 @4 p( K1 n/ T, [, r# F- J) @# W8 ^' J" b
        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
! p7 s7 o; F5 W% t                addr = base + cnt;        /* pointer arith! */
( f  [( g; y" y2 ^                val = *addr;; S! U* b; S: ?& [
                *addr = save[--i];) ], S$ Z) s# W% U
                if (val != ~cnt) {
% ?% x: b; J4 _! g+ j. x5 x$ N3 `9 c% p                        size = cnt * sizeof (long);
' P8 ^. y( q' l3 m  {4 ^" p/ V$ C2 b2 [8 q                        /* Restore the original data before leaving the function.
8 m6 O! B2 P  ~, g8 D7 `! \                         */
4 L& O$ `7 O) g( L                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {2 {' U( |7 O2 K- o
                                addr  = base + cnt;- @# f; e/ ~: w
                                *addr = save[--i];1 \+ e7 t+ X; W
                        }
) f; d  p; S8 K$ v7 o5 E1 f                        return (size);
  |0 \  ?+ K  G$ o6 `6 S4 W                }6 h) U2 x  I: v1 f. F$ s& Y
        }
3 H8 d  }) \) a6 z# ?( G  Z
6 D8 M" t1 F4 T- L+ d        return (maxsize);- ~9 ]0 E* Y# t
}0 ^0 C( p( k' v0 f( v/ \2 M9 i% C! Q' B
int dram_init(void)6 ]; Y) o4 B; W4 j* l
{( \5 U9 n8 Z0 {) ?( e+ [* {
        /* dram_init must store complete ramsize in gd->ram_size */( V4 i+ m9 ]2 W3 P& k. ~+ e3 M
        gd->ram_size = get_ram_size(, p, ?* E. u/ @; Y& y
                        (void *)CONFIG_SYS_SDRAM_BASE,4 @4 V/ u+ U! J/ ~+ E' U2 g
                        CONFIG_MAX_RAM_BANK_SIZE);
. Q/ B3 Z3 }8 W* z& b8 K* p3 f" f+ Z, {        return 0;- A9 `& g, ^3 p: z
}! E# Y+ n+ N. j: r; j9 g
2 n- E/ E4 i/ V; ?% ]7 n$ r6 B0 G

- S; X8 c- ^1 d0 e% Y8 d6 G$ x+ |* U% H- t. _8 e

; ]  {3 H7 i. U- |* D2 z6 dFLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
( L( l; V: }8 l/ b6 [
, G; h3 A1 ^* t3 ~. |2 c  c- w: q4 s- h4 `' n  l$ x0 r; E
8 k2 m/ X) i# {9 k9 l3 ?





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