Chinaunix首页 | 论坛 | 博客
  • 博客访问: 91602
  • 博文数量: 19
  • 博客积分: 760
  • 博客等级: 军士长
  • 技术积分: 260
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-30 16:30
文章存档

2011年(1)

2009年(18)

我的朋友

分类: 嵌入式

2009-07-30 17:17:11

2        修改U-boot文件,以支持nandflash读写

2.1        修改/cpu/arm920t/start.S

#include

#include

#if    defined(CONFIG_AT91RM9200DK)

#include     /*这是针对AT91RM9200DK开发板的。对于SCB2440V4也有4LED指示灯,我用来指示程序用行的进度。*/

#endif

......

/*

 * the actual start code

 */

 

start_code:

    /*

     * set the cpu to SVC32 mode

     */

    mrs    r0,cpsr

    bic    r0,r0,#0x1f

    orr    r0,r0,#0xd3

    msr    cpsr,r0

#if    defined(CONFIG_AT91RM9200DK)

    bl coloured_LED_init

    bl red_LED_on

#endif

1)        修改寄存器地址定义

#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

#define CLK_CTL_BASE 0x4C000000 /* Embest */

#define MDIV_405 0x7f << 12 /* Embest */

#define PSDIV_405 0x21 /* Embest */

#define MDIV_200 0xa1 << 12 /* Embest */

#define PSDIV_200 0x31 /* Embest */

   

......

2)        修改中断禁止部分

#if defined(CONFIG_S3C2410)

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

                       vivi也是0x7ffUBoot一直没改过来。*/

    ldr r0, =INTSUBMSK

    str r1, [r0]

#endif

3)        修改时钟设置

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

    /* default FCLK is 12 MHz ! 在这里UBoot有一个错误:以为默认时钟为120MHz。其实如果没有添加以下设置FCLK的语句,芯片内部的PLL是无效的,即FCLK 12MHzS3C24x0的芯片手册说得很明白。我一开始没有注意到这一点,是 CalmArrow提醒了我并和我讨论过,他也做过实验证实了这点。在这里对CalmArrow表示感谢和敬意!*/

    ldr    r0, =CLKDIVN

    mov    r1, #3

    str    r1, [r0]

 

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

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

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

 

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

    mov r1, #CLK_CTL_BASE /* Embest*/

    mov r2, #MDIV_200 /* mpll_200mhz Embest*/

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

    str r2, [r1, #0x04]

 

#endif    /* CONFIG_S3C2400 || CONFIG_S3C2410 */

 

4)        将从Flash启动改成从NAND Flash启动。

在以下UBoot的重定向语句段:

#ifdef    CONFIG_AT91RM9200

 

#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     {r3-r10}        /* copy from source address [r0] */

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

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

    ble    copy_loop

#endif    /* CONFIG_SKIP_RELOCATE_UBOOT */

#endif

的后面添加上:

#ifdef CONFIG_S3C2410_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 s (for nand_read())

  ldr sp, DW_STACK_START @ setup stack pointer

  mov fp, #0 @ no previous , 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_S3C2410_NAND_BOOT

 

“ldr    pc, _start_armboot”之前加入:

# if defined(CONFIG_edukit2410_LED)

@ LED1 on u-boot stage 1 is

ldr    r0, =0x56000060

ldr    r1, =0xff4af769

str    r1, [r0]

 

ldr    r0, =0x56000068

ldr    r1, =0xffff

str    r1, [r0]

 

ldr    r0, =0x21180000

ldr    r1, =0xfc

strb  r1, [r0]

#endif

//修改目的:如果看到只有LED1亮了,说明UBoot的第一阶段已完成!

  _start_armboot:    .word start_armboot  后加入:

.align 2

DW_STACK_START: .word STACK_BASE+STACK_SIZE-4

2.2        创建nandflash读函数

board/Embest/edukit2410加入NAND Flash读函数文件,拷贝vivi中的nand_read.c文件到此文件夹即可:

#include

 

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

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

#define NF_BASE 0x4e000000

 

# if defined(CONFIG_S3C2410)

 

#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 */

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

2.3        修改board/Embest/edukit2410/Makefile文件

......

OBJS := edukit2410.o nand_read.o flash.o

......

2.4        修改include/configs/edukit2410.h文件

1)        在文件末添加如下内容:

......

/*

 * Nandflash Boot

 */

#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

 

# if defined(CONFIG_S3C2410)

#define CONFIG_S3C2410_NAND_BOOT 1

/* Offset */

#define oNFCONF 0x00

#define oNFCMD 0x04

#define oNFADDR 0x08

#define oNFDATA 0x0c

#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 *)0x4e00000c)

#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

 

/*JFFS2 Support  */

#undef CONFIG_JFFS2_CMDLINE

#define CONFIG_JFFS2_NAND 1

#define CONFIG_JFFS2_DEV  "nand0"

#define CONFIG_JFFS2_PART_SIZE  0x4c0000

#define CONFIG_JFFS2_PART_OFFSET 0x40000

/*JFFS2 Support  */

 

/* USB Support 080218 */

#define CONFIG_USB_OHCI

#define CONFIG_USB_STORAGE

#define CONFIG_USB_KEYBOARD

#define CONFIG_DOS_PARTITION

#define CFG_DEVICE_DEREGISTER

#define CONFIG_SUPPORT_VFAT

#define LITTLEENDIAN

/* USB Support 080218 */

 

/*yaffs support*/

#define CFG_NAND_YAFFS1_NEW_OOB_LAYOUT  1

#define ENABLE_CMD_NAND_YAFFS 1

#define ENABLE_CMD_NAND_YAFFS_SKIPFB  1

#define CFG_NAND_YAFFS1_NEW_OOB_LAYOUT  1

/*yaffs support*/

 

#endif /* __CONFIG_H */

2)        选择串口端口,使信息能够通过uart1进行打印

因为linux内核中配置的打印端口为uart1

/*

 * select serial console configuration

 */

#define CONFIG_SERIAL2          1       /* we use SERIAL 2uart1 on edukit */

阅读(1592) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~