嵌入式开发者社区

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

作者: Mr.Loser    时间: 2014-9-11 09:33
标题: TL138 uboot是怎么区分配置两款核心板的
核心板1:DDR2 128M Byte   NAND FLASH 4G bit  p9 v8 H8 s! {2 U0 }
核心板2:DDR2 256M Byte   NAND FLASH 8G bit/ J! `  ^' Q( n
这两个核心板公共一个uboot,DDR2的配置肯定是不同的,uboot怎么检查到是哪个核心板,然后去执行相应的配置呢?
% h% e) F5 ?/ W9 y  g) e% e% |- o9 ~* L0 k: Z4 C9 P
是不是通过读NAND FLASH的ID,两款核心板NAND FLASH不同,ID也不同,这样读到了ID就知道是哪个核心板了?9 J7 ~0 g1 Y+ |! `% G: l2 R

. T) b8 r1 {4 Z: D0 r6 I
作者: 2532609929    时间: 2014-9-11 18:55
DDR通过检查最大有效地址来识别容量,具体请看uboot的common/memsize.c文件中的检查代码,也可以看如下:
/ K6 f" G  W+ r6 B( T7 w  H0 r  @/*
" q/ c8 r! ?; A' Y  q8 f3 a* Check memory range for valid RAM. A simple memory test determines
+ G. [3 H9 Q& i. M8 }' d* the actually available RAM size between addresses `base' and; e6 P3 I% i, W* V
* `base + maxsize'." e* M1 t2 `! H
*/# W) x6 v, w5 L! D6 Q6 |
long get_ram_size(long *base, long maxsize)+ J) S& s& `5 s- n2 p1 o
{
, t. q6 L4 P; n- ?# J! o* B        volatile long *addr;% g' a; P6 Q2 R3 g, O8 ]
        long           save[32];
6 T5 L; U8 r- X1 G        long           cnt;
! Q. `! d. q- t4 i4 G, o. V        long           val;: L3 @& l  z+ q* Y! Z+ [% q
        long           size;4 k  \  K# B4 _7 ~# [
        int            i = 0;
/ ~2 E) Z2 x. }
' ^" h2 ^# U( w' P, ]& l# q% \        for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
0 D# y- e- V) K* \' n1 t3 q  v1 T; m                addr = base + cnt;        /* pointer arith! */
9 g0 ]3 s" K1 Z, g2 [9 @8 s                sync ();
5 i. ~  s  ?0 [7 _: I, x7 N                save[i++] = *addr;
2 R7 D% G. `+ X; h                sync ();( t7 E4 B5 C. N& S9 I4 ~0 B
                *addr = ~cnt;- ~# c- a0 C: Z( o% H
        }- y1 y# T  }& t5 P- H. E* N
1 |8 l/ ^- a& x5 k/ f0 G4 z
        addr = base;0 ^6 p4 k& i7 p4 Z; F
        sync ();- e9 z) Y5 d; r8 i. S3 _
        save = *addr;! g; t; T# b% V$ \$ p2 j0 h! G
        sync ();
1 H8 s4 v2 H3 n  i6 R5 J; }6 |        *addr = 0;/ o" u- Y; o2 j6 V8 H9 m/ V

# f2 I- p9 Y" i& g0 y        sync ();- E" e5 ~% _4 l$ T: c
        if ((val = *addr) != 0) {; I9 }2 Z" k/ t3 r! b, ]5 p
                /* Restore the original data before leaving the function.
- _" B8 P  _- v& [3 W$ N4 V                 */
. x  V+ U! ]2 o/ F  s                sync ();* P' k. c. B9 ~: {5 ?; Z
                *addr = save;
+ o$ G: L* g* O8 a/ j                for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {4 \; h6 L# p: @/ a' O  O. o
                        addr  = base + cnt;
# [( A* H+ i, b                        sync ();% H, B3 s- m' }# t( r" d; N* G6 F
                        *addr = save[--i];
# V  D! W8 Z4 B0 q& Y3 [                }0 M" a9 t, S* p$ k2 n; n4 s2 F
                return (0);
# `4 `# ?" e2 A8 b& i0 x4 l, ]% l" t        }
$ p* S" X  t% R, ?$ [7 d
1 P4 y& T  @9 j, |        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {' D6 V( I# I6 T: [
                addr = base + cnt;        /* pointer arith! */
% u, o/ G$ v- Z  }. e5 L. T                val = *addr;% C/ c% V0 F$ o6 M) E
                *addr = save[--i];
+ ~, O; x) m* W4 H7 M2 u                if (val != ~cnt) {- g6 l# t( H+ H8 e
                        size = cnt * sizeof (long);, u, o0 v5 y) A/ ~! Z% i' L' l
                        /* Restore the original data before leaving the function.% B6 F+ q5 P; z/ R2 D" _1 f
                         */
; ~3 w  O1 }: p                        for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
( r8 j0 B3 Q. {/ k' {6 n6 M* f                                addr  = base + cnt;
* {% W" b2 A2 g2 Z# ]  Y' h                                *addr = save[--i];0 M% V  s. [& m3 H% O  L
                        }( N1 m/ H  E( _5 {1 w
                        return (size);3 S( Y5 H& \+ a3 Z) @0 P
                }+ p- Y2 J. y: c1 S, I! D
        }
  e0 Q: _/ J" t0 y
: }4 O8 c* l% d        return (maxsize);
& v+ V% Z& Z4 n% `) b5 P# y, r}7 Z  y/ e( L' Z# ]9 u- p
int dram_init(void)
; S' d7 J; Y" J# `% I& v: M{
; p9 U7 R. i5 C  ^- Z        /* dram_init must store complete ramsize in gd->ram_size */  f$ ]# s( f3 ]5 |, C
        gd->ram_size = get_ram_size(5 {0 E* ?7 _' p9 F) ]  o% ~- z8 ?' a
                        (void *)CONFIG_SYS_SDRAM_BASE,
9 w+ Z+ O! f$ E. i# V) v                        CONFIG_MAX_RAM_BANK_SIZE);$ f. M, m5 X& M( [
        return 0;
- F8 r+ I0 H" z1 s( G* n! G5 Z}# |3 @) S+ ^3 A% g! ?" s
3 ^# J$ d  R% e3 F+ V/ o. q; ?) Y
* p& a# o5 |% N" |" }
- ^+ J8 P4 d% ^+ y
7 h$ K; ~  f* w5 L. O
FLASH是通过检查FLASH内部的ID识别容量,希望对您有帮助!
: S" h# P; l/ ?; Y  t7 E! c. }; U  s* n' v5 l" H; O; Y% ~1 p% h
4 n1 U8 y# d" [$ K

. r& ?( D* Q, F4 |




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