OK6410 UBOOT移植(3)

编写程序文件nand_cp.c  放在cpu/arm1176文件夹下

#include <common.h>  
#ifdef CONFIG_S3C64XX  
#include <asm/io.h>  
#include <linux/mtd/nand.h>  
#include <asm/arch/s3c6400.h>  
  
static int nandll_read_page (uchar *buf, ulong addr, int large_block)  
{  
     int i;
  int page_size = 512;

  if (large_block==1)
     page_size = 2048;
  if (large_block==2)
    page_size = 4096;

       NAND_ENABLE_CE();

       NFCMD_REG = NAND_CMD_READ0;

       /* Write Address */
        NFADDR_REG = 0;

  if (large_block)
          NFADDR_REG = 0;

  NFADDR_REG = (addr) & 0xff;
  NFADDR_REG = (addr >> 8) & 0xff;
  NFADDR_REG = (addr >> 16) & 0xff;

  if (large_block)
    NFCMD_REG = NAND_CMD_READSTART;

       NF_TRANSRnB();

  /* for compatibility(2460). u32cannot be used. by scsuh */
  for(i=0; i < page_size; i++)
  {
               *buf++ = NFDATA8_REG;
         }

       NAND_DISABLE_CE();
        return 0;
}  
  
static int nandll_read_blocks (ulong dst_addr, ulong size, intlarge_block)  
{  
     uchar *buf = (uchar *)dst_addr;
        int i;
  uint page_shift = 9;

  if (large_block==1)
    page_shift = 11;

       /* Read pages */
  if(large_block==2)
    page_shift = 12;
 
  if(large_block == 2)
  {
   /* Read pages */
    for (i = 0; i < 4; i++, buf+=(1<<(page_shift-1)))
  {
           nandll_read_page(buf,i, large_block);
    }

 

  /* Read pages */
    for (i = 4; i < (0x3c000>>page_shift); i++,buf+=(1<<page_shift))
   {
    nandll_read_page(buf, i, large_block);
    }
  }
  else
  {
    for (i = 0; i < (0x3c000>>page_shift); i++,buf+=(1<<page_shift))
   {
            nandll_read_page(buf,i, large_block);
    }
  }

       return 0;
}  
 
 
int copy_uboot_to_ram(void)  
{  
     int large_block = 0;
  int i;
  vu_char id;
 
        NAND_ENABLE_CE();
        NFCMD_REG = NAND_CMD_READID;
        NFADDR_REG =  0x00;

  /* wait for a while */
        for (i=0; i<200; i++);
   id = NFDATA8_REG;
   id = NFDATA8_REG;

  if (id > 0x80)
    large_block = 1;
  if(id == 0xd5)
    large_block = 2;


 /* read NAND Block.
  * 128KB ->240KB because of U-Boot size increase. by scsuh
  * So, read 0x3c000 bytes not 0x20000(128KB).
  */
  return nandll_read_blocks(CONFIG_SYS_PHY_UBOOT_BASE, 0x3c000,large_block);
}  
  
#endif  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值