Chinaunix首页 | 论坛 | 博客
  • 博客访问: 667831
  • 博文数量: 237
  • 博客积分: 4285
  • 博客等级: 上校
  • 技术积分: 2701
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-15 14:05
文章分类

全部博文(237)

文章存档

2014年(2)

2013年(3)

2012年(47)

2011年(15)

2010年(68)

2009年(102)

我的朋友

分类: LINUX

2009-11-15 14:39:56

U-boot源码下载地址:
将u-boot-1.3.3.tar.bz2解压,得到文件夹u-boot-1.3.3
采用交叉编译器arm-linux-gcc 3.4.5,以下编译时先运行
export PATH=$PATH:/usr/crosstool/gcc-3.4.5-glibc-2.3.6/arm-linux/bin/
================================================================
第 1 阶段  测试环境是否正确搭建
================================================================

1)、在u-boot-1.3.3/board下找个与2410相似的开发板,这里smdk2410为例。
2)、将u-boot-1.3.3/board/smdk2410目录复制到当前目录下,并改名为2440。
3)、把smdk2410.c改名为2440.c,修改Makefile中的 COBJS := 2440.o flash.o,保存。
4)、将u-boot-1.3.3/include/configs/smdk2410.h,复制到当前目录,并改名为2440.h。
6)、在u-boot-1.3.3/Makefile中添加
2440_config : unconfig
 @$(MKCONFIG) $(@:_config=) arm arm920t 2440 NULL s3c24x0
7)、打开超级终端,切换到u-boot-1.3.3目录,敲入命令
# make 2440_config
Configuring for 2440 board...
8)、之后就可以# make了,如正常编译通过,表明环境搭建好。

================================================================
第 2 阶段
================================================================

1)、修改寄存器地址定义,将/cpu/arm920t/start.S中的
#if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410)
 /* turn off the watchdog */

# if defined(CONFIG_S3C2400)
#  define pWTCON  0x15300000
#  define INTMSK  0x14400008 /* Interupt-Controller base addresses */
#  define CLKDIVN 0x14800014 /* clock divisor register */
#else
#  define pWTCON  0x53000000
#  define INTMSK  0x4A000008 /* Interupt-Controller base addresses */
#  define INTSUBMSK 0x4A00001C
#  define CLKDIVN 0x4C000014 /* clock divisor register */
# endif
改为:
#if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440)
 /* turn off the watchdog */

# if defined(CONFIG_S3C2400)
#  define pWTCON  0x15300000
#  define INTMSK  0x14400008 /* Interupt-Controller base addresses */
#  define CLKDIVN 0x14800014 /* clock divisor register */
#else
#  define pWTCON  0x53000000
#  define INTMSK  0x4A000008 /* Interupt-Controller base addresses */
#  define INTSUBMSK 0x4A00001C
#  define CLKDIVN 0x4C000014 /* clock divisor register */
# endif
2)、修改中断禁止部分,在
# if defined(CONFIG_S3C2410)
 ldr r1, =0x3ff
 ldr r0, =INTSUBMSK
 str r1, [r0]
# endif
后加上:
# if  defined(CONFIG_S3C2440)
    ldr    r1, =0x7fff   //根据2440芯片手册,INTSUBMSK有15位可用
    ldr    r0, =INTSUBMSK
    str    r1, [r0]
# endif
3)、修改时钟设置,将
 /* FCLK:HCLK:PCLK = 1:2:4 */
 /* default FCLK is 120 MHz ! */
 ldr r0, =CLKDIVN
 mov r1, #3
 str r1, [r0]
#endif /* CONFIG_S3C2400 || CONFIG_S3C2410 */
修改为:
#define CLK_CTL_BASE        0x4C000000
#if defined(CONFIG_S3C2440)
#define MDIV_405       0x7f << 12  
#define PSDIV_405       0x21      
#endif

    /* FCLK:HCLK:PCLK = 1:4:8 */
    ldr    r0, =CLKDIVN
    mov    r1, #5
    str    r1, [r0]
  
    mrc    p15, 0, r1, c1, c0, 0        /* read ctrl register */
    orr    r1, r1, #0xc0000000          /* Asynchronous */
    mcr    p15, 0, r1, c1, c0, 0        /* write ctrl register */

#if defined(CONFIG_S3C2440)
    /*now, CPU clock is 405.00 Mhz */
    mov    r1, #CLK_CTL_BASE    
    mov    r2, #MDIV_405                /* mpll_405mhz */
    add    r2, r2, #PSDIV_405           /* mpll_405mhz */
    str    r2, [r1, #0x04]              /* MPLLCON */
#endif
#endif    /* CONFIG_S3C2400 || CONFIG_S3C2410|| CONFIG_S3C2440 */
4)、修改board/2440/lowlevel_init.S,将
#define Trp    0x0 /* 2clk */
改为:
#define Trp    0x2 /* 4clk */

#define REFCNT    1113 /* period="15".6us, HCLK="60Mhz", (2048+1-15.6*60) */
改为:
#define REFCNT    1012
5)、修改/board/2440/2440.c,将
#elif FCLK_SPEED==1  /* Fout = 202.8MHz */
#define M_MDIV 0xA1
#define M_PDIV 0x3
#define M_SDIV 0x1
修改为:
#elif FCLK_SPEED==1        /* Fout = 405MHz */
#define M_MDIV    0x7f
#define M_PDIV    0x2
#define M_SDIV    0x1

#elif USB_CLOCK==1
#define U_M_MDIV 0x48
#define U_M_PDIV 0x3
#define U_M_SDIV 0x2
改为:
#elif USB_CLOCK==1
#define U_M_MDIV    0x38
#define U_M_PDIV    0x2
#define U_M_SDIV    0x2

================================================================
第 3 阶段
================================================================

1)、修改include/configs/2440.h

#define CONFIG_S3C2410  1 /* in a SAMSUNG S3C2410 SoC     */
改为:
#define CONFIG_S3C2440
2)、将/include/common.h中的
#if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410) || defined(CONFIG_LH7A40X)
改为:
#if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410) || defined(CONFIG_LH7A40X) || defined(CONFIG_S3C2440)
3)、修改/include/s3c24x0.h,将文件中所有的
#ifdef CONFIG_S3C2410
改为:
#if defined(CONFIG_S3C2410) || defined (CONFIG_S3C2440)
4)、将/cpu/arm920t/s3c24x0/interrupts.c中的
#if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB)
修改为:
#if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB) || defined (CONFIG_S3C2440)

#elif defined(CONFIG_S3C2410)
改为:
#elif defined(CONFIG_S3C2410) || defined (CONFIG_S3C2440)
5)、将/cpu/arm920t/s3c24x0/serial.c文件中的
#if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB)
改为:
#if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB) || defined (CONFIG_S3C2440)

#elif defined(CONFIG_S3C2410)
改为:
#elif defined(CONFIG_S3C2410) || defined (CONFIG_S3C2440)
将函数static int serial_init_dev(const int dev_index)中的
 uart->UFCON = 0x07;
改为:
 uart->UFCON = 0x00;
6)、将/cpu/arm920t/s3c24x0/speed.c中的
#if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB)
改为:
#if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB) || defined (CONFIG_S3C2440)

#elif defined(CONFIG_S3C2410)
改为:
#elif defined(CONFIG_S3C2410) || defined (CONFIG_S3C2440)
在static ulong get_PLLCLK(int pllreg)中的
    m = ((r & 0xFF000) >> 12) + 8;
    p = ((r & 0x003F0) >> 4) + 2;
    s = r & 0x3;
后面加上:
#if defined(CONFIG_S3C2440)
   if (pllreg == MPLL)
    return((CONFIG_SYS_CLK_FREQ * m * 2) / (p << s));
    else if (pllreg == UPLL)
#endif

/* return HCLK frequency */
ulong get_HCLK(void)
{
    S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();

    return((clk_power->CLKDIVN & 0x2) ? get_FCLK()/2 : get_FCLK());
}
改为:
/* return HCLK frequency */
ulong get_HCLK(void)
{
    S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();

    if (clk_power->CLKDIVN & 0x6)  
    {
       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());

}
7)、/cpu/arm920t/s3c24x0/usb_ohci.c中的
#elif defined(CONFIG_S3C2410)
改为:
#elif defined(CONFIG_S3C2410) || defined (CONFIG_S3C2440)
8)、将drivers/rtc/s3c24x0_rtc.c中的
#elif defined(CONFIG_S3C2410)
改为:
#elif defined(CONFIG_S3C2410) || defined (CONFIG_S3C2440)

9)、需要在/include/s3c24x0.h文件中添加CAMDIVN定义,将
/* CLOCK & POWER MANAGEMENT (see S3C2400 manual chapter 6) */
/*                          (see S3C2410 manual chapter 7) */
typedef struct {
 S3C24X0_REG32 LOCKTIME;
 S3C24X0_REG32 MPLLCON;
 S3C24X0_REG32 UPLLCON;
 S3C24X0_REG32 CLKCON;
 S3C24X0_REG32 CLKSLOW;
 S3C24X0_REG32 CLKDIVN;
} /*__attribute__((__packed__))*/ S3C24X0_CLOCK_POWER;
改为:
/* CLOCK & POWER MANAGEMENT (see S3C2400 manual chapter 6) */
/*                          (see S3C2410 manual chapter 7) */
typedef struct {
 S3C24X0_REG32 LOCKTIME;
 S3C24X0_REG32 MPLLCON;
 S3C24X0_REG32 UPLLCON;
 S3C24X0_REG32 CLKCON;
 S3C24X0_REG32 CLKSLOW;
 S3C24X0_REG32 CLKDIVN;
#if defined (CONFIG_S3C2440)
         S3C24X0_REG32 CAMDIVN;
#endif
} /*__attribute__((__packed__))*/ S3C24X0_CLOCK_POWER;


================================================================
第 4 阶段 从Nand启动
================================================================

1)、将/cpu/arm920t/start.S中的
#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 */
替换成:
#ifdef CONFIG_S3C2440_NAND_BOOT
    /* reset NAND */
    mov    r1, #NAND_CTL_BASE
    ldr    r2, =( (7<<12)|(7<<8)|(7<<4)|(0<<0) )
    str    r2, [r1, #oNFCONF]
    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]

  /* 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, #0x20000
  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_S3C2440_NAND_BOOT
2)、在
_start_armboot: .word start_armboot
后加上
 .align     2
DW_STACK_START:  .word  STACK_BASE+STACK_SIZE-4
3)、在board/2440/加入NAND Flash读函数文件nand_read.c其内容为:

#include

#define __REGb(x)    (*(volatile unsigned char *)(x))
#define __REGi(x)    (*(volatile unsigned int *)(x))
#define NF_BASE        0x4e000000

#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 ((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 */
        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;
}
4)、修改board/2440/Makefile文件
......
OBJS := 2440.o  nand_read.o flash.o
......
5)、修改include/configs/2440.h文件,在最后一行
#endif    /* __CONFIG_H */
前加添加如下内容
/*
 * Nandflash Boot
 */
#define CONFIG_S3C2440_NAND_BOOT 1
#define STACK_BASE    0x33f00000
#define STACK_SIZE    0x8000
//#define UBOOT_RAM_BASE    0x33f80000
/* NAND Flash Controller */
#define NAND_CTL_BASE        0x4E000000
#define bINT_CTL(Nb)        __REG(INT_CTL_BASE + (Nb))
/* Offset */
#define oNFCONF            0x00
#define oNFCONT            0x04
#define oNFCMD            0x08
#define oNFADDR            0x0c
#define oNFDATA            0x10
#define oNFSTAT            0x20
#define oNFECC            0x2c
#define rNFCONF (*(volatile unsigned int *)0x4e000000)
#define rNFCONT (*(volatile unsigned int *)0x4e000004)
#define rNFCMD (*(volatile unsigned char *)0x4e000008)
#define rNFADDR (*(volatile unsigned char *)0x4e00000c)
#define rNFDATA (*(volatile unsigned char *)0x4e000010)
#define rNFSTAT (*(volatile unsigned int *)0x4e000020)
#define rNFECC (*(volatile unsigned int *)0x4e00002c)

/* GPIO */
#define GPIO_CTL_BASE        0x56000000
#define oGPIO_B            0x10
#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 */
6)、修改board/2440/u-boot.lds文件,在
   cpu/arm920t/start.o (.text)
后加上
   board/2440/lowlevel_init.o (.text)
   board/2440/nand_read.o (.text)
此时下载到2440开发板上,可以从串口看到以下信息:

U-Boot 1.3.3 (Jun  4 2009 - 14:50:34)

DRAM:  64 MB
Flash: 512 kB
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
SMDK2410 #


================================================================
第 5 阶段 添nand 驱动
================================================================

1)、修改/include/configs/2440.h
注释掉:
#define CFG_ENV_IS_IN_FLASH 1
在最后一行
#endif /* __CONFIG_H */
前面加上以下内容:
#define CFG_ENV_IS_IN_NAND 1
#define CFG_ENV_OFFSET 0X30000
#define CFG_NAND_LEGACY

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

/*----------------------------------------------------------------------
 * NAND flash settings
 */
#if defined(CONFIG_CMD_NAND)
#define CFG_NAND_BASE 0x4E000000
/* NandFlash控制器在SFR区起始寄存器地址 */
#define CFG_MAX_NAND_DEVICE 1
 /* 支持的最在Nand Flash数据 */
#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 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_S3C2440)
#define NAND_DISABLE_CE(nand) {rNFCONT |= (1<<1);}
#define NAND_ENABLE_CE(nand) {rNFCONT &= ~(1<<1);}
#endif
# if defined(CONFIG_S3C2410)
#define NAND_DISABLE_CE(nand) {rNFCONF |= (1<<11);}
#define NAND_ENABLE_CE(nand) {rNFCONF &= ~(1<<11);}
#endif

/* the following s are NOP's because S3C24X0 handles this in hardware */

#define NAND_CTL_CLRALE(nandptr)
#define NAND_CTL_SETALE(nandptr)
#define NAND_CTL_CLRCLE(nandptr)
#define NAND_CTL_SETCLE(na

#define PHYS_FLASH_1  0x00000000 /* Flash Bank #1 */

#dendptr)
/* 允许Nand Flash写校验 */
#define CONFIG_MTD_NAND_VERIFY_WRITE 1
#endif

2)、将/include/s3c24x0.h文件的
/* NAND FLASH (see S3C2410 manual chapter 6) */
typedef struct {
 S3C24X0_REG32 NFCONF;
 S3C24X0_REG32 NFCMD;
 S3C24X0_REG32 NFADDR;
 S3C24X0_REG32 NFDATA;
 S3C24X0_REG32 NFSTAT;
 S3C24X0_REG32 NFECC;
} /*__attribute__((__packed__))*/ S3C2410_NAND;
替换为:
#if defined(CONFIG_S3C2410)
/* NAND FLASH (see S3C2410 manual chapter 6) */
typedef struct {
         S3C24X0_REG32 NFCONF;
         S3C24X0_REG32 NFCMD;
         S3C24X0_REG32 NFADDR;
         S3C24X0_REG32 NFDATA;
         S3C24X0_REG32 NFSTAT;
         S3C24X0_REG32 NFECC;
} /*__attribute__((__packed__))*/ S3C2410_NAND;
#endif
#if defined (CONFIG_S3C2440)
/* NAND FLASH (see S3C2440 manual chapter 6) */
typedef struct {
         S3C24X0_REG32 NFCONF;
         S3C24X0_REG32 NFCONT;
         S3C24X0_REG32 NFCMD;
         S3C24X0_REG32 NFADDR;
         S3C24X0_REG32 NFDATA;
         S3C24X0_REG32 NFMECC0;
         S3C24X0_REG32 NFMECC1;
         S3C24X0_REG32 NFSECC;
         S3C24X0_REG32 NFSTAT;
         S3C24X0_REG32 NFESTAT0;
         S3C24X0_REG32 NFESTAT1;
         S3C24X0_REG32 NFECC;
} /*__attribute__((__packed__))*/ S3C2410_NAND;
#endif
3)、在 include/linux/mtd/nand_ids.h的结构体nand_flash_ids加入

static struct nand_flash_dev nand_flash_ids[] = {
......
    {"Samsung K9F1208U0B", NAND_MFR_SAMSUNG, 0x76, 26, 0, 3, 0x4000, 0},
    {NULL,}
};
4)、修改include/linux/mtd/nand.h

/*
 * Constants for hardware specific CLE/ALE/NCE function
*/
/* 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
注释掉,即:
#if 0
/*
 * Constants for hardware specific CLE/ALE/NCE function
*/
/* 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
5)、修改common/env_nand.c
在前面加上:
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);

extern nand_info_t nand_info[];
修改为:
extern nand_info_t nand_info[CFG_MAX_NAND_DEVICE];

6)、将
int saveenv(void)
{
 size_t total;
 int ret = 0;

 puts ("Erasing Nand...");
 if (nand_erase(&nand_info[0], CFG_ENV_OFFSET, CFG_ENV_SIZE))
  return 1;

 puts ("Writing to Nand... ");
 total = CFG_ENV_SIZE;
 ret = nand_write(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr);
 if (ret || total != CFG_ENV_SIZE)
  return 1;

 puts ("done\n");
 return ret;
}
替换为:
int saveenv(void)
{
 size_t total;
 int ret = 0;

 puts ("Erasing Nand...");
 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_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;
}

7)、将
void env_relocate_spec (void)
{
#if !defined(ENV_IS_EMBEDDED)
 size_t total;
 int ret;

 total = CFG_ENV_SIZE;
 ret = nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr);
   if (ret || total != CFG_ENV_SIZE)
  return use_default();

 if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
  return use_default();
#endif /* ! ENV_IS_EMBEDDED */
}
替换为:
void env_relocate_spec (void)
{
#if !defined(ENV_IS_EMBEDDED)
 size_t total;
 int ret;

 total = CFG_ENV_SIZE;
 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();

 if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
  return use_default();
#endif /* ! ENV_IS_EMBEDDED */
}

8)、在/board/2440/2440.c文件的末尾添加对Nand Flash 的初始化函数(在后面Nand Flash的操作都要用到)
u-boot运行至第二阶段进入start_armboot()函数。其中nand_init()函数是对nand flash的最初初始化函数。Nand_init()函数在两个文件中实现。其调用与CFG_NAND_LEGACY宏有关,如果没有定义这个宏,系统调用 drivers/nand/nand.c中的nand_init();否则调用自己在board/2440/2440.c中的nand_init()函数。这里我选择第二种方式。
在文件的最后添加以下内容:
#if defined(CONFIG_CMD_NAND)
typedef enum {
    NFCE_LOW,
    NFCE_HIGH
} NFCE_STATE;

static inline void NF_Conf(u16 conf)
{
    S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
    nand->NFCONF = conf;
}


static inline void NF_Cmd(u8 cmd)
{
    S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
    nand->NFCMD = cmd;
}

static inline void NF_CmdW(u8 cmd)
{
    NF_Cmd(cmd);
    udelay(1);
}

static inline void NF_Addr(u8 addr)
{
    S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
    nand->NFADDR = addr;
}


static inline void NF_WaitRB(void)
{
    S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
    while (!(nand->NFSTAT & (1<<0)));
}

static inline void NF_Write(u8 data)
{
    S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
    nand->NFDATA = data;
}

static inline u8 NF_Read(void)
{
    S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
    return(nand->NFDATA);
}

static inline u32 NF_Read_ECC(void)
{
    S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
    return(nand->NFECC);
}

#if defined(CONFIG_S3C2440)
static inline void NF_Cont(u16 cont)
{
    S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
    nand->NFCONT = cont;
}

static inline void NF_SetCE(NFCE_STATE s)
{
    S3C2410_NAND * const nand = S3C2410_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)
{
    S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
    nand->NFCONT |= (1<<4);
}

#else
static inline void NF_SetCE(NFCE_STATE s)
{
    S3C2410_NAND * const nand = S3C2410_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)
{
    S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
    nand->NFCONF |= (1<<12);
}
#endif

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

#define PHYS_FLASH_1  0x00000000 /* Flash Bank #1 */

#de
#define TACLS 0
#define TWRPH0 3
#define TWRPH1 0
#else
#define TACLS 0
#define TWRPH0 4
#define TWRPH1 2
#endif

#if defined(CONFIG_S3C2440)
    NF_Conf((TACLS<<12)|(TWRPH0<<8)|(TWRPH1<<4));
    NF_Cont((1<<6)|(1<<4)|(1<<1)|(1<<0));
#else
    NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0));
    /*nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); */
    /* 1 1 1 1, 1 xxx, r xxx, r xxx */
    /* En 512B 4step ECCR nFCE="H" tACLS tWRPH0 tWRPH1 */
#endif
    NF_Reset();
}

void nand_init(void)
{
    S3C2410_NAND * const nand = S3C2410_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

9)、在/board/2440/2440.h的
#include
后加上flash命令:
#define CONFIG_CMD_NAND

10)、将cpu/arm920t/s3c24x0/nand.c
中的
 #error "U-Boot legacy NAND support not available for S3C2410"
注释掉。

Nand驱动OK。

================================================================
第 6 阶段
================================================================

1)、将include/configs/2440.h中的
#define CONFIG_BOOTDELAY 3
/*#define CONFIG_BOOTARGS     "root=ramfs devfs="mount" console="ttySA0",9600" */
/*#define CONFIG_ETHADDR 08:00:3e:26:0a:5b */
#define CONFIG_NETMASK          255.255.255.0
#define CONFIG_IPADDR  10.0.0.110
#define CONFIG_SERVERIP  10.0.0.1
/*#define CONFIG_BOOTFILE "elinos-lart" */
/*#define CONFIG_BOOTCOMMAND "tftp; bootm" */
改为:
#define CONFIG_BOOTDELAY 1
#define CONFIG_BOOTARGS     "root=ramfs devfs="mount" console="ttySA0",9600"
#define CONFIG_ETHADDR 08:00:3e:26:0a:5b
#define CONFIG_NETMASK          255.255.255.0
#define CONFIG_IPADDR  10.0.0.110
#define CONFIG_SERVERIP  10.0.0.1
#define CONFIG_BOOTFILE "elinos-lart"
#define CONFIG_BOOTCOMMAND "tftp; bootm"
#define CONFIG_SETUP_MEMORY_TAGS 1
#define CONFIG_CMDLINE_TAG  1 /* enable passing of ATAGs */
2)、将
#define CFG_PROMPT  "SMDK2410 # " /* Monitor Command Prompt */
改为:
#define CFG_PROMPT  "2440 # " /* Monitor Command Prompt */


================================================================
第 7 阶段 DM9000A驱动。 这里根据硬件手册,DM9000A的nCS接到nGCS3上,其地址为0x18000000,CMD接到地址线的第2位上,即0x18000004
================================================================
1)、将include/configs/2440.h中的关于CS8900的部分替换成
/*
 * DM9000 Network Card
 */
#define CONFIG_CMD_PING
#define CONFIG_DRIVER_DM9000            1
#define CONFIG_DM9000_BASE              0x18000000
#define DM9000_IO     CONFIG_DM9000_BASE
#define DM9000_DATA   (CONFIG_DM9000_BASE + 0x04)
#define CONFIG_DM9000_USE_16BIT         1
#define CONFIG_NET_RETRY_COUNT  10
2)、经过以上修改,重新编译之后,下载到开发板上运行,发现其一旦使用网口,即会死掉,后来经过一步步更踪,发现在使用网口时,第一次向0x18000000
写数据即死掉,不往下执行。后面结过查看BWSCON寄存器,其值为0x2211D120,对于BANK3的访问,设置了[14][15]两位,其它BANK这两位并没有置1,
因此,猜想是不是由于这两位的原因,导致写数据写掉,于是重新给BWSCON赋值,在
/driver/net/dm9000x.c的eth_halt(void)函数中的
 DM9000_DBG("eth_halt\n");
后添加
*(volatile unsigned int*)(0x48000000) = 0x22111120;
重新编译,发现网口已有反应!
3)、由于驱动里用的是dm9000x,开发板上用的是dm9000A,有所不同,如果直接用uboot自带的驱动ping不能。
需要将/root/Desktop/linux2410/SRC/u-boot-1.3.3/drivers/net/dm9000x.c的内容
 /* Check packet ready or not */
 DM9000_ior(DM9000_MRCMDX); /* Dummy read */
 rxbyte = DM9000_inb(DM9000_DATA); /* Got most updated data */
在前面需要加两句:
 /* Check packet ready or not */
 DM9000_ior(DM9000_MRRH); /* The follow code is special in DM9000A */
 DM9000_ior(DM9000_MRRL);
 DM9000_ior(DM9000_MRCMDX); /* Dummy read */
 rxbyte = DM9000_inb(DM9000_DATA); /* Got most updated data */
保存重新编译即可ping通。
4)、“could not establish link” 提示和慢响应的解决方法:
将/root/Desktop/linux2410/SRC/u-boot-1.3.3/drivers/net/dm9000x.c内容中
 i = 0;
 while (!(phy_read(1) & 0x20)) { /* autonegation complete bit */
  udelay(1000);
  i++;
  if (i == 10000) {
   printf("could not establish link\n");
   return 0;
  }
 }
 /* see what we've got */
 lnk = phy_read(17) >> 12;
 printf("operating at ");
 switch (lnk) {
 case 1:
  printf("10M half duplex ");
  break;
 case 2:
  printf("10M full duplex ");
  break;
 case 4:
  printf("100M half duplex ");
  break;
 case 8:
  printf("100M full duplex ");
  break;
 default:
  printf("unknown: %d ", lnk);
  break;
 }
 printf("mode\n");
屏蔽掉。即在头和尾加上
#if 0
...
#endif

5)、在引导内核时,由于mach_type不同而造成启动不了的情况。在u-boot中,此mach_type是由board/2440/2440.c中的这段代码定义的
 /* arch number of SMDK2410-Board */
 gd->bd->bi_arch_number = MACH_TYPE_SMDK2410;
我们这里使用的内核采用的mach_type是
#define MACH_TYPE_UTU2440              5244
所以在u-boot里将其改为:
 /* arch number of SMDK2410-Board */
 gd->bd->bi_arch_number = 5244;

 

阅读(950) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:u-boot启动代码start.S详解

给主人留下些什么吧!~~