U-Boot1.3.1移植YC2440

移植U-Boot- 1.3.1 YC2440

       ARM and Linux,一个伟大的行业,鄙人正处于摸索阶段的新手。既然如此,就先从U-Boot下手,在此过程中参考了网上一些高手的资料。下面是他们的链接,感谢他们分享经验让新手快速入门、找到学习方法,再次感谢他们对于技术资料无私奉献、共享。

移植参考网上一位Tekkaman Ninja网友完成。

链接:http://blog.chinaunix.net/u1/34474/showart_410294.html

 

由于YC2440网卡芯片DM9000AEP,网卡移植参考了Weibing的一位网友。

链接:http://weibing.blogbus.com/logs/21641490.html

 

U-Boot源码:ftp://ftp.denx.de/pub/u-boot/

U-Boot- 1.3.1 还没有支持s 3c 2440,这次移植是用s 3c 2410的文件修改而成。红色为修改的地方,蓝色为运行指令、重要注释

 

一、在U-Boot中建立自己开发板类型,测试编译

1 进入U-Boot目录,修改Makefile

# tar –jxvf  u-boot- 1.3.1 .tar.bz2

# cd u-boot- 1.3.1

# gedit Makefile

//liao2440建立编译项

sbc2410x_config: unconfig

    @$(MKCONFIG) $(@:_config=) arm arm920t sbc2410x NULL s 3c 24x0

liao2440_config : unconfig

        @$(MKCONFIG) $(@:_config=) arm arm920t liao2440 liao s 3c 24x0

说明:

arm: CPU的架构(ARCH)

arm920t: CPU的类型(CPU),其对应于cpu/arm920t子目录。

liao2440: 开发板的型号(BOARD),对应于board/liao/liao2440目录。

liao: 开发者/或经销商(vender)

s 3c 24x0: 片上系统(SOC)

 

同时在“ifndef CROSS_COMPILE”之前  加上自己交叉编译器的路径,比如我使用crosstool-0.43制作的基于 2.6.24 内核和gcc-4.1.1-glibc-2.3.2ARM9TDMI交叉编译器,则:

 

CROSS_COMPILE=CROSS_COMPILE=/home/liao/crosstool/gcc- 4.1.1 -glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-

 

2 /board子目录中建立自己开发板liao2440目录

 

由于上一步板子的开发者/或经销商(vender)中填了liao,所以开发板liao2440目录一定要建在/board子目录liao目录下 ,否则编译会出错。

 

# cd board

# mkdir liao liao/liao2440

# cp -arf sbc2410x/*   liao/liao2440/

# cd liao/liao2440

# mv sbc2410x.c liao2440.c

 

修改自己开发板liao2440目录下Makefile文件

# gedit Makefile

COBJS := sbc2410x.o flash.o

 

COBJS := liao2440.o flash.o

 

3 建立配置头文件在include/configs/

# cd …/u-boot- 1.2.0 /include/configs

# cp include/configs/sbc2410x.h  include/configs/liao2440.h

 

4 测试编译是否成功

# make liao2440_config

Configuring for liao2440 board…

(如果出现:

Makefile:1927: *** 遗漏分隔符 停止。

请在Uboot的根目录下的Makefile

        @$(MKCONFIG) $(@:_config=) arm arm920t liao2440 liao)

前加上“Tab”键)

# make

 

    Ok,到这里前期准备工作完成!!!!!!!

 

二、修改U-Boot中文件,根据开发板YC2440配置

1 修改/cpu/arm920t/start.S

 

1.0 修改一些AT91RM9200定义

#include <config.h>

#include <version.h>

//#include <status_led.h>    /*这是针对AT91RM9200DK开发板*/

......

/*

 * the actual start code

 */

start_code:

    /*

     * set the cpu to SVC32 mode

     */

    mrs    r0,cpsr

    bic    r0,r0,#0x 1f

    orr    r0,r0,#0xd3

    msr    cpsr,r0

 

    //bl coloured_LED_init

    //bl red_LED_on

 

1.1修改寄存器定义

#if defined(CONFIG_S 3C 2400) || defined(CONFIG_S 3C 2410)|| defined(CONFIG_S 3C 2440)

/* turn off the watchdog */

# if defined(CONFIG_S 3C 2400)

# define pWTCON        0x15300000

# define INTMSK        0x14400008    /* Interupt-Controller base addresses */

# define CLKDIVN    0x14800014    /* clock divisor register */

# else

# define pWTCON        0x53000000

# define INTMSK        0x 4A 000008    /* Interupt-Controller base addresses */

# define INTSUBMSK    0x 4A 00001C

# define CLKDIVN    0x 4C 000014    /* clock divisor register */

# endif

# define CLK_CTL_BASE        0x 4C 000000

# if defined(CONFIG_S 3C 2440)

# define MDIV_405       0x 7f << 12

# define PSDIV_405       0x21

# endif

# if defined(CONFIG_S 3C 2410)

# define MDIV_200        0xa1 << 12

# define PSDIV_200        0x31

# endif

/*这一段为后面修改时钟定义的一些参数*/

 

1.2修改中断禁止部分

# if defined(CONFIG_S 3C 2400) || defined(CONFIG_S 3C 2410) || defined(CONFIG_S 3C 2440)

    ldr      r0, =pWTCON

    mov    r1, #0x0

    str      r1, [r0]

 

     /*

     * mask all IRQs by setting all bits in the INTMR - default

     */

    mov    r1, #0xffffffff

    ldr     r0, =INTMSK

    str     r1, [r0]

# if defined(CONFIG_S 3C 2410)

    ldr    r1, =0x7ff     //根据2410芯片手册,INTSUBMSK11位可用,

                       //vivi也是0x7ff,不知为什么UBoot一直没改过来。

    ldr    r0, =INTSUBMSK

    str    r1, [r0]

# endif

# if  defined(CONFIG_S 3C 2440)

    ldr    r1, =0x7fff   //根据2440芯片手册,INTSUBMSK15位可用

    ldr    r0, =INTSUBMSK

    str    r1, [r0]

# endif

 

1.3 修改时钟设置

/*时钟控制逻辑单元能够产生s 3c 2440需要的时钟信号,包括CPU使用的主频FCLK,AHB总线使用的HCLK,APB总线设备使用的PCLK2440里面的两个锁相环(PLL),其中一个对应FCLKHCLKPCLK,另外一个对应UCLK(48MHz)*/

/* FCLK:HCLK:PCLK = 1:4:8 */

    ldr    r0, =CLKDIVN

    mov    r1, #5

    str    r1, [r0]

/*

下面协处理器指令是用来把CPU的模式设置成Asynchronous 模式,为什么要这样做?s 3c 2440datasheet说得很清楚,具体可在datasheet中搜索R1_nFR1_iA内容。至于R1_nFR1_iA的值可以在vivi源码的s 3c 2440.h中得到。

单从指令上看,下面指令的作用把协处理器p15的寄存器c1的最高两位置1,仔细看过《arm 体系结构与编程》的朋友可能会发现个问题:《arm 体系结构与编程》里面说 p15 bit30bit31是保留的,那么下面的指令又怎么会有意义呢?其实《arm 体系结构与编程》里面说这两个bit是保留的是针对arm7的,对arm9s 3c 2440并不适用。

*/

    mrc    p15, 0, r1, c1, c0, 0        /*read ctrl register   liao*/

    orr    r1, r1, #0xc0000000         /*Asynchronous  liao*/

    mcr    p15, 0, r1, c1, c0, 0      /*write ctrl register liao*/

 

# if defined(CONFIG_S 3C 2440)

    /*now, CPU clock is 405.00 Mhz  */

    mov    r1, #CLK_CTL_BASE

    mov    r2, #MDIV_405                   /* mpll_405mhz    liao*/

    add    r2, r2, #PSDIV_405             /* mpll_405mhz    liao*/

    str    r2, [r1, #0x04]               /* MPLLCON liao */

# endif

# if defined(CONFIG_S 3C 2410)

    /*now, CPU clock is 202.8 Mhz   liao*/

    mov    r1, #CLK_CTL_BASE    /* liao*/

    mov    r2, #MDIV_200                   /* mpll_200mhz    liao*/

    add    r2, r2, #PSDIV_200             /* mpll_200mhz    liao*/

    str    r2, [r1, #0x04]               /* MPLLCON liao */

# endif

# endif    /* CONFIG_S 3C 2400 || CONFIG_S 3C 2410|| CONFIG_S 3C 2440 */

/*时钟设置参照vivi代码,主频405MHZ*/

 

1.4 Flash启动改为从NAND Flash启动(24102440不同,参照vivi

# if 0

# ifndef CONFIG_SKIP_RELOCATE_UBOOT

relocate:                   /* relocate U-Boot to RAM       */

    adr    r0, _start        /* r0 <- current position of code   */

    ldr    r1, _TEXT_BASE        /* test if we run from flash or RAM */

    cmp     r0, r1                /* don't reloc during debug         */

    beq     stack_setup

 

    ldr    r2, _armboot_start

    ldr    r3, _bss_start

    sub    r2, r3, r2        /* r2 <- size of armboot            */

    add    r2, r0, r2        /* r2 <- source end address         */

 

copy_loop:

    ldmia    r0!, {r3-r10}        /* copy from source address [r0]    */

    stmia    r1!, {r3-r10}        /* copy to   target address [r1]    */

    cmp    r0, r2            /* until source end addreee [r2]    */

    ble    copy_loop

# endif    /* CONFIG_SKIP_RELOCATE_UBOOT */

# endif

/*参照vivi代码,nandflash拷贝*/

# ifdef CONFIG_S 3C 2440_NAND_BOOT  

    @ reset NAND

    mov    r1, #NAND_CTL_BASE

    ldr    r2, =( (7<<12)|(7<<8)|(7<<4)|(0<<0) )

    str    r2, [r1, #oNFCONF]     /*这些宏在includes/configs/liao2440.h中定义*/

    ldr    r2, [r1, #oNFCONF]

 

    ldr    r2, =( (1<<4)|(0<<1)|(1<<0) ) @ Active low CE Control

    str    r2, [r1, #oNFCONT]

    ldr    r2, [r1, #oNFCONT]

 

    ldr    r2, =(0x6)        @ RnB Clear

    str    r2, [r1, #oNFSTAT]

    ldr    r2, [r1, #oNFSTAT]

   

    mov    r2, #0xff        @ RESET command

    strb    r2, [r1, #oNFCMD]

 

    mov r3, #0                   @ wait

nand1:

    add  r3, r3, #0x1

    cmp r3, #0xa

    blt   nand1

 

nand2:

    ldr   r2, [r1, #oNFSTAT]      @ wait ready

    tst    r2, #0x4

    beq  nand2

 

 

    ldr    r2, [r1, #oNFCONT]

    orr    r2, r2, #0x2        @ Flash Memory Chip Disable

    str    r2, [r1, #oNFCONT]

/*汇编调用C函数,初始化栈*/

@ get read to call C functions (for nand_read())

    ldr   sp, DW_STACK_START       @ setup stack pointer

    mov fp, #0                    @ no previous frame, so fp=0

 

@ copy U-Boot to RAM

    ldr   r0, =TEXT_BASE

    mov     r1, #0x0

  mov  r2, #0x30000

    bl    nand_read_ll

/*nand_read_lluboot拷贝代码入口函数,r0r1r2为入口参数

tst  r0#0x0r0为函数返回值*/

    tst    r0, #0x0

    beq  ok_nand_read

 

bad_nand_read:

loop2:    b     loop2          @ infinite loop

 

 

ok_nand_read:

@ verify

    mov r0, #0

    ldr   r1, =TEXT_BASE

  mov r2, #0x400     @ 4 bytes * 1024 = 4K-bytes

go_next:

    ldr   r3, [r0], #4

  ldr   r4, [r1], #4

    teq   r3, r4

    bne  notmatch

    subs r2, r2, #4

    beq  stack_setup

bne  go_next

 

notmatch:

loop3:     b     loop3         @ infinite loop

 

#endif @ CONFIG_S 3C 2440_NAND_BOOT

#ifdef CONFIG_S 3C 2410_NAND_BOOT

@ reset NAND

mov r1, #NAND_CTL_BASE

    ldr r2, =0xf830 @ initial value

    str r2, [r1, #oNFCONF]

    ldr r2, [r1, #oNFCONF]

 

    bic r2, r2, #0x800 @ enable chip

    str r2, [r1, #oNFCONF]

 

    mov r2, #0xff @ RESET command

    strb r2, [r1, #oNFCMD]

 

  mov r3, #0 @ wait

nand1:

    add r3, r3, #0x1

    cmp r3, #0xa

    blt nand1

 

nand2:

    ldr r2, [r1, #oNFSTAT] @ wait ready

    tst r2, #0x1

    beq nand2

 

    ldr r2, [r1, #oNFCONF]

    orr r2, r2, #0x800 @ disable chip

    str r2, [r1, #oNFCONF]

 

@ get read to call C functions (for nand_read())

    ldr sp, DW_STACK_START @ setup stack pointer

  mov fp, #0 @ no previous frame, so fp=0

 

@ copy U-Boot to RAM

  ldr r0, =TEXT_BASE

    mov r1, #0x0

    mov r2, #0x30000

    bl nand_read_ll

    tst r0, #0x0

    beq ok_nand_read

 

bad_nand_read:

loop2: b loop2 @ infinite loop

 

 

ok_nand_read:

@ verify

    mov r0, #0

    ldr r1, =TEXT_BASE

    mov r2, #0x400 @ 4 bytes * 1024 = 4K-bytes

go_next:

  ldr r3, [r0], #4

    ldr r4, [r1], #4

    teq r3, r4

  bne notmatch

  subs r2, r2, #4

  beq stack_setup

  bne go_next

 

notmatch:

loop3: b loop3 @ infinite loop

 

#endif @ CONFIG_S 3C 2410_NAND_BOOT

 

1.5 调出start.S前,利用点灯大法查看程序运行位置

ldr  pc_start_armboot 之前加入LED

mov    r1, #GPIO_CTL_BASE

add    r1, r1, #oGPIO_F

ldr    r2,=0x55aa

str    r2, [r1, #oGPIO_CON]

mov    r2, #0xff

str    r2, [r1, #oGPIO_UP]

mov    r2, #0xe0

str    r2, [r1, #oGPIO_DAT]

/*YC2440开发板有4LEDGPIO_F[4:7],点亮一个LED,下面函数进入第二阶段*/

ldr  pc_start_armboot

_start_armboot:      .word start_armboot

.align     2                 

DW_STACK_START:  .word  STACK_BASE+STACK_SIZE-4

/*栈空间是从高地址向低地址增长,用于调用nand_read_ll函数时设置占空间,STACK_BASE STACK_SIZE定义在后面/include/configs/liao2440.h */

 

2 board/liao/liao2440加入NAND Flash读函数文件,复制vivinand_read.c文件

#include <config.h>

 

#define __REGb(x)    (*(volatile unsigned char *)(x))

#define __REGi(x)    (*(volatile unsigned int *)(x))

#define NF_BASE        0x4e000000

 

#if defined(CONFIG_S 3C 2440)         /*s 3c 2440部分*/

 

#define NFCONF        __REGi(NF_BASE + 0x0)

#define NFCONT        __REGi(NF_BASE + 0x4)

#define NFCMD        __REGb(NF_BASE + 0x8)

#define NFADDR        __REGb(NF_BASE + 0xC)

#define NFDATA        __REGb(NF_BASE + 0x10)

#define NFSTAT        __REGb(NF_BASE + 0x20)

 

//#define GPDAT        __REGi(GPIO_CTL_BASE+oGPIO_F+oGPIO_DAT)

 

#define NAND_CHIP_ENABLE  (NFCONT &= ~(1<<1))

#define NAND_CHIP_DISABLE (NFCONT |=  (1<<1))

#define NAND_CLEAR_RB      (NFSTAT |=  (1<<2))

#define NAND_DETECT_RB      { while(! (NFSTAT&(1<<2)) );}

 

#define BUSY 4

inline void wait_idle(void) {

    while(!(NFSTAT & BUSY));

    NFSTAT |= BUSY;

}

 

#define NAND_SECTOR_SIZE    512

#define NAND_BLOCK_MASK        (NAND_SECTOR_SIZE - 1)

 

/* low level nand read function */

int

nand_read_ll(unsigned char *buf, unsigned long start_addr, int size)

{

    int i, j;

/*

下面if保证对flash的读操作是从某一页的页头开始的,也就是保证start_addr[0:8]位都为0

本次flash的一页的大小位512-bytes,也就是从0x00x1ff */

    if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {

        return -1;    /* invalid alignment */

    }

 

    NAND_CHIP_ENABLE;

 

    for(i=start_addr; i < (start_addr + size);) {

        /* READ0 */

        NAND_CLEAR_RB;       

        NFCMD = 0;

 

        /* Write Address */

/*下面这个送地址的过程最难懂的一部分,为什么送进nand flash的地址忽略了bit8,纵观整个for(i) 循环,i并不是一个随机的地址,而应该是每一页的首地址。其实nand flash并不是忽略了bit8这个地址,而是bit8早就被定下来了,就是上面的NFCMD = 0;语句,(K 9F 1208U0B)支持从半页开始读取,从而它有两个读的命令,分别是0x00(从一页的上半页开始读) 0x01(从一页的下半页开始读),当取0x00时,bit8=0,当取0x01 bit8=1*/

        NFADDR = i & 0xff;

        NFADDR = (i >> 9) & 0xff;

        NFADDR = (i >> 17) & 0xff;

        NFADDR = (i >> 25) & 0xff;

 

        NAND_DETECT_RB;

 

        for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {

            *buf = (NFDATA & 0xff);

            buf++;

        }

    }

    NAND_CHIP_DISABLE;

    return 0;

}

#endif

 

#if defined(CONFIG_S 3C 2410)          /*s 3c 2410部分*/

 

#define NFCONF __REGi(NF_BASE + 0x0)

#define NFCMD __REGb(NF_BASE + 0x4)

#define NFADDR __REGb(NF_BASE + 0x8)

#define NFDATA __REGb(NF_BASE + 0xc)

#define NFSTAT __REGb(NF_BASE + 0x10)

#define BUSY 1

 

inline void wait_idle(void) {

    int i;

    while(!(NFSTAT & BUSY))

      for(i=0; i<10; i++);

}

/* low level nand read function */

int

nand_read_ll(unsigned char *buf, unsigned long start_addr, int size)

{

    int i, j;

    if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {

        return -1; /* invalid alignment */

    }

    /* chip Enable */

    NFCONF &= ~0x800;

    for(i=0; i<10; i++);

    for(i=start_addr; i < (start_addr + size);)

{

      /* READ0 */

        NFCMD = 0;

        /* Write Address */

        NFADDR = i & 0xff;

        NFADDR = (i >> 9) & 0xff;

        NFADDR = (i >> 17) & 0xff;

        NFADDR = (i >> 25) & 0xff;

        wait_idle();

        for(j=0; j < NAND_SECTOR_SIZE; j++, i++)

{

     *buf = (NFDATA & 0xff);

                   buf++;

        }

    }

    /* chip Disable */

    NFCONF |= 0x800; /* chip disable */

    return 0;

}

# endif

 

3.修改board/liao/liao2440/Makefile文件

......

OBJS := liao2440.o nand_read.o flash.o

......

 

4.修改include/configs/liao2440.h文件

在文件末尾添加定义

/*2410 2440 nand flash控制寄存器不同,不能混用*/

/*

 * Nandflash Boot

 */

#define STACK_BASE    0x 33f 00000

#define STACK_SIZE    0x8000

//#define UBOOT_RAM_BASE    0x 33f 80000

/* NAND Flash Controller */

#define NAND_CTL_BASE        0x4E000000

#define bINT_CTL(Nb)        __REG(INT_CTL_BASE + (Nb))

 

# if defined(CONFIG_S 3C 2440)

#define CONFIG_S 3C 2440_NAND_BOOT 1

/* Offset */

#define oNFCONF 0x00

#define oNFCONT 0x04

#define oNFCMD 0x08

#define oNFADDR 0x 0c

#define oNFDATA 0x10

#define oNFSTAT 0x20

#define oNFECC 0x 2c

#define rNFCONF (*(volatile unsigned int *)0x4e000000)

#define rNFCONT (*(volatile unsigned int *)0x4e000004)

#define rNFCMD (*(volatile unsigned char *)0x4e000008)

#define rNFADDR (*(volatile unsigned char *)0x4e 00000c )

#define rNFDATA (*(volatile unsigned char *)0x4e000010)

#define rNFSTAT (*(volatile unsigned int *)0x4e000020)

#define rNFECC (*(volatile unsigned int *)0x4e 00002c )

#endif

 

/* GPIO */

#define GPIO_CTL_BASE        0x56000000

#define oGPIO_F            0x50

#define oGPIO_CON       0x0   /* R/W, Configures the pins of the port */

#define oGPIO_DAT        0x4    /* R/W,    Data register for port */

#define oGPIO_UP        0x8    /* R/W, Pull-up disable register */

 

# if defined(CONFIG_S 3C 2410)

#define CONFIG_S 3C 2410_NAND_BOOT 1

/* Offset */

#define oNFCONF 0x00

#define oNFCMD 0x04

#define oNFADDR 0x08

#define oNFDATA 0x 0c

#define oNFSTAT 0x10

#define oNFECC 0x14

#define rNFCONF (*(volatile unsigned int *)0x4e000000)

#define rNFCMD (*(volatile unsigned char *)0x4e000004)

#define rNFADDR (*(volatile unsigned char *)0x4e000008)

#define rNFDATA (*(volatile unsigned char *)0x4e 00000c )

#define rNFSTAT (*(volatile unsigned int *)0x4e000010)

#define rNFECC (*(volatile unsigned int *)0x4e000014)

#define rNFECC0 (*(volatile unsigned char *)0x4e000014)

#define rNFECC1 (*(volatile unsigned char *)0x4e000015)

#define rNFECC2 (*(volatile unsigned char *)0x4e000016)

#endif

# endif    /* __CONFIG_H */

 

5.修改board/liao/liao2440/lowlevel_init.S文件

依照开发板的内存区的配置情况, 修改board/liao/liao2440/lowlevel_init.S文件

......

/* REFRESH parameter */

#define REFEN             0x1    /* Refresh enable */

#define TREFMD             0x0    /* CBR(CAS before RAS)/Auto refresh */

#define Trc             0x3    /* 7clk */

#define Tchr             0x2    /* 3clk */

 

#if defined(CONFIG_S 3C 2440)

#define Trp             0x2    /* 4clk */

#define REFCNT             1012

#else

#define Trp            0x0    /* 2clk */

#define REFCNT            0x0459

#endif

/*到这里第一阶段配置全部完成,下面就是C函数初始化配置*/

 

6 修改board/liao/liao2440/liao2440.c

修改其对GPIOPLL的配置,参阅开发板硬件说明和2440芯片手册

#define FCLK_SPEED 1

 

#if FCLK_SPEED==0           /* Fout = 203MHz, Fin = 12MHz for Audio */

#define M_MDIV   0xC3

#define M_PDIV    0x4

#define M_SDIV    0x1

#elif FCLK_SPEED==1

//#define M_MDIV    0x 5c

//#define M_PDIV    0x4

//#define M_SDIV    0x0

 

#if defined(CONFIG_S 3C 2440)

#define M_MDIV    0x 7f

#define M_PDIV    0x2

#define M_SDIV    0x1

#endif

 

#if defined(CONFIG_S 3C 2410)

#define M_MDIV   0xA1

#define M_PDIV    0x3

#define M_SDIV    0x1

#endif

 

#endif

 

#define USB_CLOCK 1

 

#if USB_CLOCK==0

#define U_M_MDIV      0xA1

#define U_M_PDIV       0x3

#define U_M_SDIV       0x1

#elif USB_CLOCK==1

 

#if defined(CONFIG_S 3C 2410)

#define U_M_MDIV    0x48

#define U_M_PDIV    0x3

#endif

 

#if defined(CONFIG_S 3C 2440)

#define U_M_MDIV    0x38

#define U_M_PDIV    0x2

#endif

#define U_M_SDIV    0x2

......

 

/* set up the I/O ports */

gpio->GPACON = 0x007FFFFF;

……

// gpio->GPFCON = 0x000055AA;

gpio->GPFCON = 0x5500; /*for LED*/

......

/* arch number of S 3C 2440 -Board */

#if defined(CONFIG_S 3C 2440)

gd->bd->bi_arch_number = MACH_TYPE_S 3C 2440 ;

#endif

#if defined(CONFIG_S 3C 2410)

gd->bd->bi_arch_number = MACH_TYPE_SMDK2410;

#endif

 

/* adress of boot parameters */

gd->bd->bi_boot_params = 0x30000100;

icache_enable();

dcache_enable();

gpio->GPFDAT = 0xc0; /*for LED*/

 

return 0;

 

7. 实现NAND Flash的读写,再次修改/include/configs/liao2440.h

......

/*

 * High Level Configuration Options

 * (easy to change)

 */

#define CONFIG_ARM920T        1    /* This is an ARM920T Core    */

//#define CONFIG_S 3C 2410        1    /* in a SAMSUNG S 3C 2410 SoC     */

//#define CONFIG_SBC2410X      1    /* on a friendly-arm SBC-2410X Board  */

#define    CONFIG_S 3C 2440      1    /* in a SAMSUNG S 3C 2440 SoC     */

#define  CONFIG_liao2440     1    /* on a SAMSUNG liao2440 Board  */

/*很多地方调用CONFIG_S 3C 2440,在这里定义,CONFIG_liao2440是针对本开发板配置的宏控制*/

......

/*

 * Command line configuration.

 */

#include <config_cmd_default.h>

 

#define CONFIG_CMD_ASKENV

#define CONFIG_CMD_CACHE

#define CONFIG_CMD_DATE

#define CONFIG_CMD_DHCP

#define CONFIG_CMD_ELF

#define CONFIG_CMD_PING

#define CONFIG_CMD_NAND

#define CONFIG_CMD_REGINFO

……

#define    CFG_LONGHELP                /* undef to save memory        */

#define    CFG_PROMPT   "[liao2440]#"        /*Monitor Command Prompt  */

#define    CFG_CBSIZE        256                 /* Console I/O Buffer Size    */

……

#undef  CFG_CLKS_IN_HZ              /* everything, incl board info, in Hz */

#define    CFG_LOAD_ADDR             0x30008000    /* default load address   */

/*linux kernel放在这里执行*/

/* the PWM TImer 4 uses a counter of 15625 for 10 ms, so we need */

……

/* timeout values are in ticks */

#define CFG_FLASH_ERASE_TOUT   (5*CFG_HZ) /* Timeout for Flash Erase */

#define CFG_FLASH_WRITE_TOUT  (5*CFG_HZ) /* Timeout for Flash Write */

//#define  CFG_ENV_IS_IN_FLASH    1

#define    CFG_ENV_IS_IN_NAND    1

#define CFG_ENV_OFFSET  0X30000         /*u-boot空间为192k*/

#define CFG_NAND_LEGACY

/*注意:网上很多地方都有关于CONFIG_CMD_NAND CFG_NAND_LEGACYdrivers/mtd/nand/nand.c中的nand_init()函数以及board/qljt/qljt2440/qljt2440.c中的nand_init()函数这四个东西的关系,请参考附录。*/

#define CFG_ENV_SIZE    0x10000   /* Total Size of Environment Sector */

/*----------------------------------------------------------------------

 * NAND flash settings

 */

#if (CONFIG_CMD_NAND)

#define CFG_NAND_BASE 0x4E000000   /* NandFlash控制器在SFR区起始寄存器地址 */

#define CFG_MAX_NAND_DEVICE 1

#define SECTORSIZE 512               /* 1页的大小 */

#define NAND_SECTOR_SIZE SECTORSIZE

#define NAND_BLOCK_MASK 511          /* 页掩码 */

/*在其它地方定义过,留着也不碍事*/

 

#define ADDR_COLUMN 1                /* 一个字节的Column地址 */

#define ADDR_PAGE 3                  /* 3字节的页块地址*/

#define ADDR_COLUMN_PAGE 4           /* 总共4字节的页块地址*/

 

#define NAND_ChipID_UNKNOWN 0x00     /* 未知芯片的ID */

#define NAND_MAX_FLOORS 1

#define NAND_MAX_CHIPS 1             /* Nand Flash命令层底层接口函数 */

 

//#define NAND_WAIT_READY(nand) NF_WaitRB()

//#define NAND_DISABLE_CE(nand)  NF_SetCE(NFCE_HIGH)

//#define NAND_ENABLE_CE(nand)   NF_SetCE(NFCE_LOW)

//#define WRITE_NAND_COMMAND(d, adr)    NF_Cmd(d)

//#define WRITE_NAND_COMMANDW(d, adr) NF_CmdW(d)

//#define WRITE_NAND_ADDRESS(d, adr)      NF_Addr(d)

//#define WRITE_NAND(d, adr)          NF_Write(d)

//#define READ_NAND(adr)               NF_Read()

 

#define WRITE_NAND_ADDRESS(d, adr) {rNFADDR = d;}

#define WRITE_NAND(d, adr) {rNFDATA = d;}

#define READ_NAND(adr) (rNFDATA)

#define NAND_WAIT_READY(nand) {while(!(rNFSTAT&(1<<0)));}

#define WRITE_NAND_COMMAND(d, adr) {rNFCMD = d;}

#define WRITE_NAND_COMMANDW(d, adr) NF_CmdW(d)

#if defined(CONFIG_S 3C 2440)

#define NAND_DISABLE_CE(nand) {rNFCONT |= (1<<1);}

#define NAND_ENABLE_CE(nand) {rNFCONT &= ~(1<<1);}

#endif

# if defined(CONFIG_S 3C 2410)

#define NAND_DISABLE_CE(nand) {rNFCONF |= (1<<11);}

#define NAND_ENABLE_CE(nand) {rNFCONF &= ~(1<<11);}

#endif

/* the following functions are NOP's because S 3C 24X0 handles this in hardware */

#define NAND_CTL_CLRALE(nandptr)

#define NAND_CTL_SETALE(nandptr)

#define NAND_CTL_CLRCLE(nandptr)

#define NAND_CTL_SETCLE(nandptr)

#define CONFIG_MTD_NAND_VERIFY_WRITE 1

……

#endif     /* __CONFIG_H */

 

8.在一些文件中添加CONFIG_S 3C 2440,使得原来s 3c 2410代码可以编译进来

8.1 /include/common.h文件的第474行:

#if defined(CONFIG_S 3C 2400) || defined(CONFIG_S 3C 2410) || defined(CONFIG_LH 7A 40X) || defined(CONFIG_S 3C 2440)

 

8.2 /include/s 3c 24x0.h文件的第859599110148404行改为:

#if defined(CONFIG_S 3C 2410) || defined (CONFIG_S 3C 2440)

 

顺便加入NAND Flash寄存器定义(160行附近)CAMDIVN定义(128行附近)

typedef struct {

         S 3C 24X0_REG32   LOCKTIME;

         S 3C 24X0_REG32   MPLLCON;

         S 3C 24X0_REG32   UPLLCON;

         S 3C 24X0_REG32   CLKCON;

         S 3C 24X0_REG32   CLKSLOW;

         S 3C 24X0_REG32   CLKDIVN;

#if defined(CONFIG_S 3C 2440)

         S 3C 24X0_REG32   CAMDIVN;

#endif

} /*__attribute__((__packed__))*/ S 3C 24X0_CLOCK_POWER;

......

#if defined(CONFIG_S 3C 2410)

/* NAND FLASH (see S 3C 2410 manual chapter 6) */

typedef struct {

         S 3C 24X0_REG32   NFCONF;

         S 3C 24X0_REG32   NFCMD;

         S 3C 24X0_REG32   NFADDR;

         S 3C 24X0_REG32   NFDATA;

         S 3C 24X0_REG32   NFSTAT;

         S 3C 24X0_REG32   NFECC;

} /*__attribute__((__packed__))*/ S 3C 2410_NAND;

#endif

#if defined (CONFIG_S 3C 2440)

/* NAND FLASH (see S 3C 2440 manual chapter 6) */

typedef struct {

         S 3C 24X0_REG32   NFCONF;

         S 3C 24X0_REG32   NFCONT;

         S 3C 24X0_REG32   NFCMD;

         S 3C 24X0_REG32   NFADDR;

         S 3C 24X0_REG32   NFDATA;

         S 3C 24X0_REG32   NFMECC0;

         S 3C 24X0_REG32   NFMECC1;

         S 3C 24X0_REG32   NFSECC;

         S 3C 24X0_REG32   NFSTAT;

         S 3C 24X0_REG32   NFESTAT0;

         S 3C 24X0_REG32   NFESTAT1;

         S 3C 24X0_REG32   NFECC;

} /*__attribute__((__packed__))*/ S 3C 2410_NAND;

#endif

 

8.3 cpu/arm920t/s 3c 24x0/interrupts.c文件的第3338181行:

#if defined(CONFIG_S 3C 2400) || defined (CONFIG_S 3C 2410) || defined (CONFIG_TRAB) || defined (CONFIG_S 3C 2440)

 

#elif defined(CONFIG_S 3C 2410) || defined (CONFIG_S 3C 2440)

 

defined(CONFIG_VCMA9) || defined(CONFIG_liao2440)

/*添加defined(CONFIG_liao2440),使得原来sbc2410X的代码可以编译进来*/

 

 

8.4 /cpu/arm920t/s 3c 24x0/serial.c文件的第2226行:

#if defined(CONFIG_S 3C 2400) || defined (CONFIG_S 3C 2410) || defined (CONFIG_TRAB) || defined (CONFIG_S 3C 2440)

#elif defined(CONFIG_S 3C 2410) || defined (CONFIG_S 3C 2440)

 

8.5 /cpu/arm920t/s 3c 24x0/speed.c文件的第3337行:

#if defined(CONFIG_S 3C 2400) || defined (CONFIG_S 3C 2410) || defined (CONFIG_TRAB) || defined (CONFIG_S 3C 2440)

#elif defined(CONFIG_S 3C 2410) || defined (CONFIG_S 3C 2440)

 

static ulong get_PLLCLK(int pllreg)

{

    ......

 

    m = ((r & 0xFF000) >> 12) + 8;

    p = ((r & 0x 003F 0) >> 4) + 2;

    s = r & 0x3;

#if defined(CONFIG_S 3C 2440)

    if (pllreg == MPLL)

    return((CONFIG_SYS_CLK_FREQ * m * 2) / (p << s));

    else if (pllreg == UPLL)

#endif

    return((CONFIG_SYS_CLK_FREQ * m) / (p << s));

}

 

/* return FCLK frequency */

ulong get_FCLK(void)

{

    return(get_PLLCLK(MPLL));

}

 

/* return HCLK frequency */

ulong get_HCLK(void)

{

    S 3C 24X0_CLOCK_POWER * const clk_power = S 3C 24X0_GetBase_CLOCK_POWER();

    if (clk_power->CLKDIVN & 0x6)   

    {

        /*CAMDIVN 12中定义*/

      if ((clk_power->CLKDIVN & 0x6)==2)       

              return(get_FCLK()/2);

         if ((clk_power->CLKDIVN & 0x6)==6)      

              return((clk_power->CAMDIVN & 0x100) ? get_FCLK()/6 : get_FCLK()/3);        

        if ((clk_power->CLKDIVN & 0x6)==4)       

              return((clk_power->CAMDIVN & 0x200) ? get_FCLK()/8 : get_FCLK()/4);        

        return(get_FCLK());

     }

     else      

     {

        return(get_FCLK());

     }

     //return((clk_power->CLKDIVN & 0x2) ? get_FCLK()/2 : get_FCLK());

}

 

8.6 cpu/arm920t/s 3c 24x0/usb_ohci.c文件的第45行:

#elif defined(CONFIG_S 3C 2410) || defined(CONFIG_S 3C 2440)

 

8.7 drivers/rtc/s 3c 24x0_rtc.c文件的第35行:

#elif defined(CONFIG_S 3C 2410) || defined(CONFIG_S 3C 2440)

 

8.8 cpu/arm920t/s 3c 24x0/usb.c文件的第31行:

#elif defined(CONFIG_S 3C 2410) || defined (CONFIG_S 3C 2440)

8.9 cpu/arm920t/s 3c 24x0/i 2c .c文件的第35

#elif defined(CONFIG_S 3C 2410) || defined (CONFIG_S 3C 2440)

6685142150174行改为:

#if defined(CONFIG_S 3C 2410) || defined (CONFIG_S 3C 2440)

 

8.10 drivers/usb/usb_ohci.c文件的68行附近

#if defined(CONFIG_ARM920T) || /

    defined(CONFIG_S 3C 2400) || /

    defined(CONFIG_S 3C 2410) || /

    defined(CONFIG_S 3C 2440) || /

    defined(CONFIG_440EP) || /

    defined(CONFIG_PCI_OHCI) || /

    defined(CONFIG_MPC5200)

 

9.include/linux/mtd/nand_ids.h的结构体nand_flash_ids加入

static struct nand_flash_dev nand_flash_ids[] = {

......

    {"Samsung K 9F 1208U0B",  NAND_MFR_SAMSUNG, 0x76, 26, 0, 3, 0x4000, 0},

    {NULL,}

......

};

/*下面说说上面结构体的8个参数是怎么得出来的,以便日后再次移植的时候会更换nand flash*/

/*

1.“厂家 型号”:这个从nand flashdatasheet就可以直接找到了吧。

2. 生产商的编号:也就是datasheet里面的Maker code,它也同时被存放在nand flash里面的ID(nand flash应该有一个读ID命令的)信息里面)。

3. 本模块的编号:也就是datasheet里面的device code,跟Maker code一样它也被放到ID信息里面。

4. 总共容纳的地址位数:也就是有效的地址位数。针对于本flash(K 9F 1208U 0M )可以参考它的datasheet7页。

5. 一页所存储的字节数是否为256个:针对于本flash(K 9F 1208U 0M )可以参考它的datasheet7页。

6. 地址需要多少字节数减一(行列地址总共):举个例子可能更容易明白,第4点中可以知道本flash(K 9F 1208U 0M )26位,而对本flash地址的写入每次只能写8位,所以至少要写4次才能把26位地址写入本flash4次的写入针对于编程来说就是[0:3],所以本falsh相对于该结构体的该变量的值是3.

7. 擦除1block的大小:简单来说就是1block的大小,本flash 1block=32 pages1 page=512 bytes,所以 1 block=512x32=16 k-bytes,也就是0x4000

8. 是否为16位总线:本flash地址和数据总线共用,都是8位的,所以上面值为0

*/

 

修改include/linux/mtd/nand.h

/*

 * Constants for hardware specific CLE/ALE/NCE function

*/

#if 0

/* Select the chip by setting nCE to low */

#define NAND_CTL_SETNCE        1

/* Deselect the chip by setting nCE to high */

#define NAND_CTL_CLRNCE        2

/* Select the command latch by setting CLE to high */

#define NAND_CTL_SETCLE        3

/* Deselect the command latch by setting CLE to low */

#define NAND_CTL_CLRCLE        4

/* Select the address latch by setting ALE to high */

#define NAND_CTL_SETALE        5

/* Deselect the address latch by setting ALE to low */

#define NAND_CTL_CLRALE        6

/* Set write protection by setting WP to high. Not used! */

#define NAND_CTL_SETWP        7

/* Clear write protection by setting WP to low. Not used! */

#define NAND_CTL_CLRWP        8

#endif

10.修改lib_arm/board.c

......

#include <common.h>

#include <command.h>

#include <malloc.h>

#include <devices.h>

#include <version.h>

#include <net.h>

#include <s 3c 2410.h>

......

static int display_banner (void)

{

       S 3C 24X0_GPIO * const gpio = S 3C 24X0_GetBase_GPIO();

        gpio->GPFDAT = 0x80;

/*在串口初始化和console初始化完成,串口输出信息之前,LED1LED2LED3会亮起*/

       printf ("/n/n%s/n/n", version_string);

       debug ("U-Boot code: %08lX -> %08lX  BSS: -> %08lX/n",

              _armboot_start, _bss_start, _bss_end);

#ifdef CONFIG_MODEM_SUPPORT

       debug ("Modem Support enabled/n");

#endif

#ifdef CONFIG_USE_IRQ

       debug ("IRQ Stack: %08lx/n", IRQ_STACK_START);

       debug ("FIQ Stack: %08lx/n", FIQ_STACK_START);

#endif

 

       return (0);

}

……

void start_armboot (void)

{

         init_fnc_t **init_fnc_ptr;

         char *s;

#ifndef CFG_NO_FLASH

         ulong size;

#endif

 

#if defined(CONFIG_VFD) || defined(CONFIG_LCD)

         unsigned long addr;

#endif

 

         S 3C 24X0_GPIO * const gpio = S 3C 24X0_GetBase_GPIO();

......

 

         gpio->GPBDAT = 0x00;

/*在进入命令提示符之前,四个LED会同时亮起*/

         /* main_loop() can return to retry autoboot, if so just run it again. */

         for (;;) {

                   main_loop ();

         }

         /* NOTREACHED - no way out of command loop except booting */

}

 

11.修改common/env_nand.c

#ifdef CONFIG_INFERNO

#error CONFIG_INFERNO not supported yet

#endif

 

int nand_legacy_rw (struct nand_chip* nand, int cmd,

           size_t start, size_t len,

           size_t * retlen, u_char * buf);

extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];

extern int nand_legacy_erase(struct nand_chip *nand, size_t ofs, size_t len, int clean);

 

/* info for NAND chips, defined in drivers/nand/nand.c */

extern nand_info_t nand_info[CFG_MAX_NAND_DEVICE];

……

#else /* ! CFG_ENV_OFFSET_REDUND */

int saveenv(void)

{

       ulong total;

       int ret = 0;

 

       puts ("Erasing Nand...");

       //if (nand_erase(&nand_info[0], CFG_ENV_OFFSET, CFG_ENV_SIZE))

       if (nand_legacy_erase(nand_dev_desc + 0, CFG_ENV_OFFSET, CFG_ENV_SIZE, 0))  

              return 1;

 

       puts ("Writing to Nand... ");

       total = CFG_ENV_SIZE;

       //ret = nand_write(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr);

       ret = nand_legacy_rw(nand_dev_desc + 0,

              0x00 | 0x02, CFG_ENV_OFFSET, CFG_ENV_SIZE,

              &total, (u_char*)env_ptr);

 

       if (ret || total != CFG_ENV_SIZE)

              return 1;

 

       puts ("done/n");

       return ret;

}

……

#else /* ! CFG_ENV_OFFSET_REDUND */

/*

 * The legacy NAND code saved the environment in the first NAND device i.e.,

 * nand_dev_desc + 0. This is also the behaviour using the new NAND code.

 */

void env_relocate_spec (void)

{

#if !defined(ENV_IS_EMBEDDED)

       ulong total;

       int ret;

 

       total = CFG_ENV_SIZE;

       //ret = nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr);

       ret = nand_legacy_rw(nand_dev_desc + 0, 0x01 | 0x02, CFG_ENV_OFFSET,

              CFG_ENV_SIZE, &total, (u_char*)env_ptr);

      if (ret || total != CFG_ENV_SIZE)

              return use_default();

 

12. /board/liao/liao2440/liao2440.c文件末尾添加NAND Flash初始化函数

u-boot运行至第二阶段进入start_armboot()函数。其中nand_init()函数是对nand flash的最初初始化函数。nand_init()函数在两个文件中实现。其调用与CFG_NAND_LEGACY宏有关,如果没有定义这个宏,系统调用 drivers/nand/nand.c中的nand_init();否则调用自己在board/liao/liao2440/liao2440.c中的nand_init()函数。这里我选择第二种方式。

#if (CFG_CMD_NAND)

typedef enum {

NFCE_LOW,

NFCE_HIGH

} NFCE_STATE;

static inline void NF_Conf(u16 conf)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       nand->NFCONF = conf;

}

static inline void NF_Cmd(u8 cmd)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       nand->NFCMD = cmd;

}

static inline void NF_CmdW(u8 cmd)

{

       NF_Cmd(cmd);

       udelay(1);

}

static inline void NF_Addr(u8 addr)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       nand->NFADDR = addr;

}

static inline void NF_WaitRB(void)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       while (!(nand->NFSTAT & (1<<0)));

}

static inline void NF_Write(u8 data)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       nand->NFDATA = data;

}

static inline u8 NF_Read(void)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       return(nand->NFDATA);

}

static inline u32 NF_Read_ECC(void)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       return(nand->NFECC);

}

 

#if defined(CONFIG_S 3C 2440)         /*2440部分*/

static inline void NF_Cont(u16 cont)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       nand->NFCONT = cont;

}

static inline void NF_SetCE(NFCE_STATE s)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       switch (s) {

              case NFCE_LOW:

                     nand->NFCONT &= ~(1<<1);

                     break;

 

              case NFCE_HIGH:

                     nand->NFCONT |= (1<<1);

                     break;

                  }

}

static inline void NF_Init_ECC(void)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       nand->NFCONT |= (1<<4);

}

#else                  /*2410 部分*/

static inline void NF_SetCE(NFCE_STATE s)

{

    S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

    switch (s) {

    case NFCE_LOW:

        nand->NFCONF &= ~(1<<11);

        break;

    case NFCE_HIGH:

        nand->NFCONF |= (1<<11);

        break;

    }

}

 

static inline void NF_Init_ECC(void)

{

    S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

    nand->NFCONF |= (1<<12);

}    

#endif

 

#if (CONFIG_COMMANDS & CFG_CMD_NAND)

       extern ulong nand_probe(ulong physadr);

 

static inline void NF_Reset(void)

{

       int i;

       NF_SetCE(NFCE_LOW);

       NF_Cmd(0xFF); /* reset command */

       for(i = 0; i < 10; i++); /* tWB = 100ns. */

       NF_WaitRB(); /* wait 200~500us; */

       NF_SetCE(NFCE_HIGH);

}

static inline void NF_Init(void)

{

#if 0 /* a little bit too optimistic */

       #define TACLS 0

       #define TWRPH0 3

       #define TWRPH1 0

#else

       #define TACLS 0

       #define TWRPH0 4

       #define TWRPH1 2

#endif

 

#if defined(CONFIG_S 3C 2440)

    NF_Conf((TACLS<<12)|(TWRPH0<<8)|(TWRPH1<<4));

       NF_Cont((1<<6)|(1<<4)|(1<<1)|(1<<0));

#else

nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)

|(TWRPH0<<4)|(TWRPH1<<0);

#endif

/* 1 1 1 1, 1 xxx, r xxx, r xxx */

/* En 512B 4step ECCR nFCE=H tACLS tWRPH0 tWRPH1 */

       NF_Reset();

}

void nand_init(void)

{

       S 3C 2410_NAND * const nand = S 3C 2410_GetBase_NAND();

       NF_Init();

#ifdef DEBUG

       printf("NAND flash probing at 0x%.8lX/n", (ulong)nand);

#endif

       printf ("%4lu MB/n", nand_probe((ulong)nand) >> 20);

}

#endif

 

13.DM9000AEP网卡移植

U-Boot- 1.3.1 U-Boot-1.2.0DM9000的驱动源码有些变化,增加了参数中提取MAC地址的语句,避免U-Boot-1.2.0的网卡打印信息不正确。由于杨创YC2440配置网卡芯片是DM9000AEP,并不是完全兼容DM9000,对dm9000x.c做一些修改。

 

13.1修改/include/configs/liao2440.h

/*

 * Hardware drivers

 */

//#define CONFIG_DRIVER_CS8900   1     /* we have a CS8900 on-board */

//#define CS8900_BASE        0x19000300

//#define CS8900_BUS16             1 /* the Linux driver does accesses as shorts */

/* CONFIG_DM9000_BASE参数根据开发板设置*/

#define CONFIG_DRIVER_DM9000 1

#define CONFIG_DM9000_BASE 0x18000300

#define DM9000_IO CONFIG_DM9000_BASE

#define DM9000_DATA (CONFIG_DM9000_BASE+4)

#define CONFIG_DM9000_USE_16BIT

 

13.2修改drivers/dm9000x.c

……

/* For module input parameter */

//static int media_mode = DM9000_AUTO;  /* use full duplex mode */

static int media_mode = DM9000_100MFD;

static u8 nfloor = 0;

……

void eth_halt(void);

void eth_halt_true(void);

static int dm9000_probe(void);

……

/* NIC Type: FASTETHER, HOMERUN, LONGRUN */

//identify_nic();

/* GPIO0 on pre-activate PHY */

       DM9000_iow(DM9000_GPR, 0x00);   /*REG_ 1F bit0 activate phyxcer */

 

/* Set PHY */

       //set_PHY_mode();

       /* copy from set_PHY_mode, do not set phy mode */

DM9000_iow(DM9000_GPCR, 0x01);  /* Let GPIO0 output */

    DM9000_iow(DM9000_GPR, 0x00);   /* Enable PHY */

/* Program operating register */

       //DM9000_iow(DM9000_NCR, 0x0);   /* only intern phy supported by now */

       DM9000_iow(DM9000_TCR, 0); /* TX Polling clear */

       DM9000_iow(DM9000_BPTR, 0x 3f );  /* Less 3Kb, 200us */

……

/* Set Node address */

//     for (i = 0; i < 6; i++)

//            ((u16 *) bd->bi_enetaddr)[i] = read_srom_word(i);

        if (is_zero_ether_addr(bd->bi_enetaddr) ||

/*U-Boot 1.3.1 相比1.2.0打印网卡信息有所改变*/

……

        DM9000_iow(DM9000_IMR, IMR_PAR);        /* Enable TX/RX interrupt mask */

#if 0

        i = 0;

        while (!(phy_read(1) & 0x20)) { /* autonegation complete bit */

                udelay(1000);

......

        default:

                printf("unknown: %d ", lnk);

                break;

        }

        printf("mode/n");

#endif

/*could not establish link提示和慢响应的解决方法*/

       return 0;

}

……

/*

  Stop the interface.

  The interface is stopped when it is brought.

*/

void eth_halt(void){}

 

void eth_halt_true(void)

{

       DM9000_DBG("eth_halt/n");

 

       /* RESET devie */

       phy_write(0, 0x8000);   /* PHY RESET */

       DM9000_iow(DM9000_GPR, 0x01);   /* Power-Down PHY */

       DM9000_iow(DM9000_IMR, 0x80);   /* Disable all interrupt */

       DM9000_iow(DM9000_RCR, 0x00);   /* Disable RX */

}

……

       /* Check packet ready or not */

       DM9000_ior(DM9000_MRRH);

    DM9000_ior(DM9000_MRRL);      //must add this two read

 

       DM9000_ior(DM9000_MRCMDX);     /* Dummy read */

       rxbyte = DM9000_inb(DM9000_DATA);     /* Got most updated data */

 

       if (rxbyte == 0)

                return 0;

 

        /* Status check: this byte must be 0 or 1 */

        if (rxbyte > 1) {

                DM9000_iow(DM9000_RCR, 0x00);   /* Stop Device */

                DM9000_iow(DM9000_ISR, 0x80);   /* Stop INT request */

                DM9000_DBG("rx status check: %d/n", rxbyte);

                return;

        }

……

/* Fill the phyxcer register into REG_ 0C */

       DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);

       DM9000_iow(DM9000_EPCR, 0xc);   /* Issue phyxcer read command */

       // udelay(100);            /* Wait read complete */

       udelay(1000);         /* Wait read complete */

       DM9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer read command */

       val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL);

……

        DM9000_iow(DM9000_EPCR, 0xa);   /* Issue phyxcer write command */

// udelay(500);            /* Wait write complete */

        udelay(1000);           /* Wait write complete */

        DM9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer write command */

        DM9000_DBG("phy_write(reg:%d, value:%d)/n", reg, value);

}

#endif                          /* CONFIG_DRIVER_DM9000 */

 

三、交叉编译U-Boot

# cd u-boot

# make

如何利用已有U-BootSDRAM调试U-Boot

1 board/liao/liao2440/config.mk文件中修改TEXT_BASE=0x33000000,避免新的U-Boot与原来地址重复。

2 cpu/arm920t/start.S中屏蔽cpu_init_crit,此函数会将SDRAM清空一次,后果可想而知

#ifndef CONFIG_SKIP_LOWLEVEL_INIT

@bl cpu_init_crit

#endif

3 1.4节中加入一段代码,判断U-Boot是否在SDRAM,从而是否需要拷贝

@ get read to call C functions (for nand_read())

  ldr   sp, DW_STACK_START       @ setup stack pointer

  mov fp, #0                    @ no previous frame, so fp=0

 

@ test uboot on sdram so decided whether need copy

  adr r0,_start

  ldr r1,_TEXT_BASE

  cmp r0,r1

  beq stack_setup

/*这一段代码测试uboot是否在sdram,若在,跳过拷贝直接进入stack_setup。由于采用自带的u-bootsdram调试自己制作的,所以此时不会拷贝flash上的uboot*/

@ copy U-Boot to RAM

  ldr   r0, =TEXT_BASE

  mov     r1, #0x0

  mov r2, #0x30000

  bl    nand_read_ll

  tst    r0, #0x0

  beq  ok_nand_read

4 启动原来的U-Boot,调试新的

# tftp 33000000 u-boot.bin

# go 33000000

 

 

附录:

1.u-boot- 1.3.1 (不含u-boot-1.3.1)nand_init函数的调用关系,它的调用是被“CONFIG_COMMANDS&CFG_CMD_NAND”和“CFG_NAND_LEGACY”控制的,1:表示该值为真,0:表示该值为假

A /drivers/mtd/nand/nand.c中的nand_init()函数

B /board/liao/liao2440/liao2440.c中的nand_init()函数

CONFIG_COMMAND

&CFG_CMD_NAND

CFG_NAND_LEGACY

A

B

         0

          0

      0

       0

         0

          1

      0

       0

         1

          0

      1

       1

         1

          1

      0

       1

2.u-boot- 1.3.1 (u-boot-1.3.1)nand_init函数的调用关系,它的调用是被“CONFIG_CMD_NAND”和“CFG_NAND_LEGACY”控制的。

CONFIG_CMD_NAND

CFG_NAND_LEGACY

A

B

         0

          0

      0

       0

         0

          1

      0

       0

         1

          0

      1

       1

         1

          1

      0

       1

 

你可能感兴趣的:(c,struct,command,cmd,Flash,asynchronous)