原创 u-boot-2010.03在tq6410上的移植详解(六)

2010-9-26 17:36 1378 10 10 分类: MCU/ 嵌入式

原创文章版权所有!如需转载,请注明出处: http://hi.baidu.com/liushuiyue1/myhome谢谢合作!!!!!


3)drivers/mtd/nand/nand_base.c



在2095行处红色字体为修改部分:


static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,


                    size_t *retlen, const uint8_t *buf)


{


      struct nand_chip *chip = mtd->priv;


      int ret;



      #if defined(CONFIG_SYS_NAND_YAFFS_WRITE)


             int oldopsmode = 0;


             if(mtd->rw_oob==1)


             {


                    size_t oobsize =mtd->oobsize;  


                    size_t datasize = mtd->writesize;


                    int i=0;


                    uint8_t oobtemp[oobsize];


                    int datapages = 0;


                    datapages = len/(datasize);


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


                    {


                           memcpy((void *)oobtemp,(void *)(buf+datasize*(i+1)),oobsize);


                           memmove((void *)(buf+datasize*(i+1)),(void *)(buf+datasize*(i+1)+oobsize),(datapages-(i+1))*(datasize)+(datapages-1)*oobsize);


                           memcpy((void *)(buf+(datapages)*(datasize+oobsize)-oobsize),(void *)(oobtemp),oobsize);


                    }


             }


      #endif



      /* Do not allow reads past end of device */


      if ((to + len) > mtd->size)


             return -EINVAL;


      if (!len)


             return 0;


      nand_get_device(chip, mtd, FL_WRITING);


      chip->ops.len = len;


      chip->ops.datbuf = (uint8_t *)buf;


      #if !defined(CONFIG_SYS_NAND_YAFFS_WRITE)


      chip->ops.oobbuf = NULL;


      #endif


      #if defined(CONFIG_SYS_NAND_YAFFS_WRITE)


             if(mtd->rw_oob!=1)


             {


                    chip->ops.oobbuf = NULL;


             }


             else


             {


                    chip->ops.oobbuf = (uint8_t*)(buf+len);


                    chip->ops.ooblen = mtd->oobsize;


                    oldopsmode = chip->ops.mode;


                    chip->ops.mode = MTD_OOB_RAW;


             }    


      #endif


      ret = nand_do_write_ops(mtd, to, &chip->ops);



      *retlen = chip->ops.retlen;



      nand_release_device(mtd);


      #if defined(CONFIG_SYS_NAND_YAFFS_WRITE)


             chip->ops.mode = oldopsmode;      


      #endif



      return ret;


}

文章评论0条评论)

登录后参与讨论
我要评论
0
10
关闭 站长推荐上一条 /2 下一条