嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit2 \( Z6 Z, U. L
核心板2:DDR2 256M Byte   NAND FLASH 8G bit& \; b/ L( C: z4 @: D
这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?2 V. }3 v% \3 [6 ^. B7 j& A/ \

$ |2 ~7 t/ Y6 R% x是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?( Q- W# @9 m" e

# X# f. M: k. D% O4 ?# J/ @) b, i
作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
$ r7 n  w4 J% q4 R7 x& w/*
  H& H8 b/ ]7 p! o+ I0 h* Check memory range for valid RAM. A simple memory test determines
/ f3 S7 ~4 H) k  s, i: V; [4 `0 Y* the actually available RAM size between addresses `base' and
6 ]8 A# g  L+ [* `base + maxsize'.+ ^: n  Q* D; B
*/1 ~  g  M8 g) P: @+ R3 p
long get_ram_size(long *base, long maxsize)
8 _: Q6 b) x; w: D3 A{# C& f. c, `# M
        volatile long *addr;/ Q! r) Y+ q$ p4 \% t( W5 c7 y) x
        long           save[32];
" N% U3 n/ ]  [0 @" j        long           cnt;4 d5 w6 `" q* e6 k
        long           val;
+ c6 U9 [5 U9 m9 G: x        long           size;
* ]" k8 Q' V* @6 i7 j0 r  c        int            i = 0;8 X0 e! }0 F% ?6 f+ \$ `. s

: M* \0 t% L: Q! X        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
. k2 v/ m4 n) ^5 ~! e4 \* b                addr = base + cnt;        /* pointer arith! */- _( J5 R/ h( b7 O) y) l! |$ ~
                sync ();
/ ~3 E0 m% D! u) |% J                save[i++] = *addr;
3 k/ |. R7 f8 ]0 j2 L) e5 h                sync ();+ G: o2 D8 Q: Z3 I2 {* U
                *addr = ~cnt;
9 }' I& `$ N5 q! f' i7 H; g  B        }- X) ?5 f7 w0 |0 f4 w7 g. g1 o

4 [6 S) G' P# b$ P8 p        addr = base;
' T: G7 a! R5 V6 g. ~; v" H        sync ();  }# ]. Y* X& E9 c& D, B# F. O
        save = *addr;
- W: v) [4 |& W3 F        sync ();& m6 i" y3 S0 d, H3 ~" S
        *addr = 0;4 R$ W) U! _; P3 b$ i
( C5 L# V/ o/ f. M, y: @- s
        sync ();
/ [3 J& u: m, I2 @! Z+ d  l$ O        if ((val = *addr) != 0) {
& B2 ?7 ]* F1 K  ]2 F3 q% U                /* Restore the original data before leaving the function.1 v/ }) W8 N4 Q+ m5 v
                 */* q! X* K" w2 I; ^, O
                sync ();
4 ?; y( s& t  n% N& J' s                *addr = save;; D* ?9 h0 o8 i9 \
                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {- ~' E$ o% i6 x0 L
                        addr  = base + cnt;
  t$ l! E& M8 \- E! A                        sync ();
4 n5 }  O5 q+ W" p                        *addr = save[--i];
% K8 q  ^1 V7 a2 M6 X                }+ ]6 r2 x- {0 y+ R
                return (0);
; l1 A/ J) x5 I( K- a: N5 j        }
; y* S/ E7 |, G" @/ }. A1 f; l  q2 N" E. q+ W
        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
" l2 z* h% w/ Y3 h$ c: Y                addr = base + cnt;        /* pointer arith! */4 b2 q! i- N7 ], Y  J
                val = *addr;
, h" V7 J7 G+ c& d, X                *addr = save[--i];
/ @( n$ O* n# ~- y2 [! f! _, G. ^6 g. P                if (val != ~cnt) {
. d7 \6 I# Q' j$ D2 W2 @                        size = cnt * sizeof (long);7 Y. y: B& R) ?7 Z/ [7 X$ O
                        /* Restore the original data before leaving the function.# ^# [4 R  f& o! K6 r9 Q1 ^' P( C; G
                         */) T9 O3 D9 D3 _3 q
                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {5 B4 y& X$ \1 Z- ]- Y  G
                                addr  = base + cnt;3 Y. x) P: f9 L& w  w' _9 F
                                *addr = save[--i];5 D) a- |. c* x4 v$ K
                        }1 N2 A! r( @# l5 A1 j& i
                        return (size);
  o3 j, i% @6 Z3 C0 e  O- U                }
" K& N; R! `( V$ Z( u. `        }# M/ z( F2 e# W* J) ^

$ _  ?4 K9 d, R$ Z5 E  r$ ?        return (maxsize);
2 x1 K, X4 ?3 b/ C$ `7 w( N! O}3 {2 f, W4 H% ]( Q: C
int dram_init(void)
7 K( |8 D# ^& n: o# E8 Z) G4 i{6 @$ c  e+ @7 n
        /* dram_init must store complete ramsize in gd->ram_size */
+ Y* F1 I: a% D* L$ k# E        gd->ram_size = get_ram_size(
, y% m, O5 {' ^# c& s                        (void *)CONFIG_SYS_SDRAM_BASE,
, h  Q8 L8 g& _! R/ _                        CONFIG_MAX_RAM_BANK_SIZE);
! O# H1 f3 Y0 v2 s( T; T        return 0;" q( W, U6 T3 t
}
0 D. Z6 W: {, q" n
( E2 c4 G" L5 v( s
, }% d& Q% O" T% ?* Y9 j% i9 L6 Q: b  N; k3 u
5 E9 s/ c, @2 o9 M; N5 i2 n; h
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
, n, ]/ H2 G2 w- a8 v+ C& s1 a+ s

8 _9 t- L- ~$ A# W6 A( P  C

$ C  D8 l! o# J0 \. D( f  G- c9 M




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