在s3c2440上linux镜像在nand flash中吗,U-boot在S3C2440上的移植详解(五)

int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, u_char *buffer)

{

int rval;

size_t left_to_write = *length;

size_t len_incl_bad;

u_char *p_buffer = buffer;

#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support    if(nand->rw_oob==1)

{

size_t oobsize = nand->oobsize;

size_t datasize = nand->writesize;

int datapages = 0;

if (((*length)%(nand->oobsize+nand->writesize)) != 0)

{

printf ("Attempt to write error length data!\n");

return -EINVAL;

}

datapages = *length/(datasize+oobsize);

*length = datapages*datasize;

left_to_write = *length;

}

#endif

/* Reject writes, which are not page aligned */

if ((offset & (nand->writesize - 1)) != 0 ||

(*length & (nand->writesize - 1)) != 0) {

printf ("Attempt to write non page aligned data\n");

return -EINVAL;

}

len_incl_bad = get_len_incl_bad (nand, offset, *length);

if ((offset + len_incl_bad) >= nand->size) {

printf ("Attempt to write outside the flash area\n");

return -EINVAL;

}

#if !defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support

if (len_incl_bad == *length) {

rval = nand_write (nand, offset, length, buffer);

if (rval != 0)

printf ("NAND write to offset %llx failed %d\n",

offset, rval);

return rval;

}

#endif

while (left_to_write > 0) {

size_t block_offset = offset & (nand->erasesize - 1);

size_t write_size;

WATCHDOG_RESET ();

if (nand_block_isbad (nand, offset & ~(nand->erasesize - 1))) {

printf ("Skip bad block 0x%08llx\n",

offset & ~(nand->erasesize - 1));

offset += nand->erasesize - block_offset;

continue;

}

#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support

if(nand->skipfirstblk==1)

{

nand->skipfirstblk=0;

printf ("Skip the first good block %llx\n", offset & ~(nand->erasesize - 1));

offset += nand->erasesize - block_offset;

continue;

}

#endif

if (left_to_write < (nand->erasesize - block_offset))

write_size = left_to_write;

else

write_size = nand->erasesize - block_offset;

printf("\rWriting at 0x%llx -- ",offset); //add yaffs2 file system support

rval = nand_write (nand, offset, &write_size, p_buffer);

if (rval != 0) {

printf ("NAND write to offset %llx failed %d\n",

offset, rval);

*length -= left_to_write;

return rval;

}

left_to_write -= write_size;

printf("%d%% is complete.",100-(left_to_write/(*length/100)));

offset += write_size;

#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support

if(nand->rw_oob==1)

{

p_buffer += write_size+(write_size/nand->writesize*nand->oobsize);

}

else

{

p_buffer += write_size;

}

#else

p_buffer += write_size;

#endif

}

return 0;

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值