【原创】u-boot移植-->连载五

uboot移植参考说明:

       该移植有部分移植参考互联网资源,如有侵权,请与我联系。大部分为自己原创,如有转载请注明出处,该技术仅供学习交流,不可商用。------小盒子  于哈尔滨2009年05月08日整理

12.board/hyt24x0/文件夹下新建一个.c文件<read_nand.c>

文件内容如下:

 

/*

*******************************************************************************

*                                        Copyright (c) 2008 - 2010 Small.BoxCorp. All rights reserved.                                       

*

* FILENAME

*                   read_nand.c

*

* VERSION

*                   V1.00

*

* HISTORY

*                   2008/10/09 21:14          Ver 1.0 Created by Small.Box

*

* REMARK   

*

*

*******************************************************************************

*/

 

#include <common.h>

#include <s3c2410.h>

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

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

#define NF_BASE 0x4e000000

#if defined(CONFIG_S3C2440)

#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<<0)) );}

#define BUSY 4

#define NAND_SECTOR_SIZE 512

#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)

void nand_reset(void)

{

     int i;

 

    NFCONF=(7<<12)|(7<<8)|(7<<4);

    NFCONT=(0<<13)|(0<<12)|(0<<10)|(0<<9)|(0<<8)|(1<<6)|(1<<5)|(1<<4)|(1<<1)|(1<<0);

    NAND_CHIP_ENABLE;

     NFCMD = 0xff;

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

           ;

         NAND_DETECT_RB;

         NAND_CHIP_DISABLE;

}

 

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

       }

  */

 

       NAND_CHIP_ENABLE;

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

       ;

 

       i=start_addr;

       while(i<start_addr+size)

       {

              NFCMD=0;

              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;i++,j++)

              {

                     *buf=(NFDATA & 0xff);

                     buf++;

              }

       }

       NAND_CHIP_DISABLE;

 

       return 0;

}

#endif //CONFIG_S3C2440

#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

#define NAND_SECTOR_SIZE 512

#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)

inline void wait_idle(void) {

    int i;

    while(!(NFSTAT & BUSY))

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

}

void nand_reset(void)

{

     int i;

 

    NFCONF = (1<<15)|(1<<12)|(1<<11)|(7<<8)|(7<<4)|(7);

    NFCONF &= ~0x800;

     NFCMD = 0xff;

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

           ;

         wait_idle();

         NFCONF |= 0x800;

}

 

 

/* low level nand read function */

int

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

{

    int i, j;

    // Remove by heyunhuan at 20081008

    /*

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

        return -1;

    }

    */

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

添加完后保存并退出。同时修改在目录下面的Makefile文件

OBJS     := hyt24x0.o flash.o read_nand.o

SOBJS   := lowlevel_init.o

由于时间关系,uboot的移植过程,未来得及整理,这里整理出来的有点慢了。下次我会注意的。
请关注《【原创】u-boot移植-->连载六》
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值