当前位置:   article > 正文

flash_erase擦除NAND flash坏块失败_libmtd: error!: memerase64 ioct1 failed for eraseb

libmtd: error!: memerase64 ioct1 failed for eraseblock 3196 (mtd2

板子使用busybox文件系统,带了mtd-utils的工具,包括flash_erase。首先查看帮助信息:

[root@M3250 ~]# flash_erase --h
Usage: flash_erase [options] MTD_DEVICE <start offset> <block count>
Erase blocks of the specified MTD device.
Specify a count of 0 to erase to end of device.
  -j, --jffs2       format the device for jffs2
  -N, --noskipbad   don't skip bad blocks
  -u, --unlock      unlock sectors before erasing
  -q, --quiet       display progress messages
      --silent      same as --quiet
      --help        display this help and exit
      --version     output version information and exit
[root@M3250 ~]#


看样子flash_erase默认不擦除坏块的,但可以使用-N选项启用这个功能。但是结果如下:

[root@M3250 ~]# flash_erase -N /dev/mtd4 0 0
Erasing 128 Kibyte @ 0 --  0 % nand_erase_nand: attempt to erase a bad block at page 0x0001ff00
Erasing 128 Kibyte @ 2nand_erase_nand: attempt to erase a bad block at page0x0001ff40
Erasing 128 Kibyte @ 40000 -- 50 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 2
 (mtd4)
        error 5 (Input/output error)
flash_erase: error!: /dev/mtd4: MTD Erase failure
             error 5 (Input/output error)
Erasing 128 Kibyte @ 60000 -- 75 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 3
 (mtd4)
        error 5 (Input/output error)
flash_erase: error!: /dev/mtd4: MTD Erase failure
             error 5 (Input/output error)
Erasing 128 Kibyte @ 60000 -- 100 % complete


还是擦不了。看了下内核的代码,在/drivers/mtd/nand/nand_base.c中nand_erase_nand函数有这么一段:

while (len) {
/*
* heck if we have a bad block, we do not erase bad blocks !
*/
if (nand_block_checkbad(mtd, ((loff_t) page) << chip->page_shift, 0, allowbbt)) {
printk(KERN_WARNING "%s:attempt to erase a bad block "
"at page 0x%08x\n", __func__, page);
instr->state = MTD_ERASE_FAILED;
goto erase_exit;
}

结论就是linux内核不支持擦除坏块。

解决办法:在uboot中使用"nand scrub"擦除。


附上自己写的mtd擦除程序:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <mtd/mtd-user.h>
  5. #include <sys/ioctl.h>
  6. int main(int argc, char *argv[])
  7. {
  8. int dev_fd;
  9. int result;
  10. erase_info_t erase;
  11. mtd_info_t mtd;
  12. int rt = 0;
  13. if (argc !=2) {
  14. printf("%s:input a argument like /dev/mtdX\n", argv[0]);
  15. rt = -1;
  16. goto exit;
  17. }
  18. printf("the device you want to erase is %s\n", argv[1]);
  19. dev_fd = open (argv[1], O_SYNC | O_RDWR);
  20. if (dev_fd < 0) {
  21. printf("open %s failed\n", argv[1]);
  22. perror("erase mtd");
  23. rt = -1;
  24. goto exit;
  25. }
  26. if (ioctl(dev_fd, MEMGETINFO, &mtd) < 0) {
  27. printf("%s:MTD getinfo failed\n", argv[1]);
  28. perror("get mtd info");
  29. rt = -1;
  30. goto close;
  31. }
  32. erase.start = 0;
  33. erase.length = mtd.size;
  34. if (ioctl (dev_fd, MEMERASE, &erase) < 0) {
  35. printf("%s: erase failed\n", argv[1]);
  36. perror("erase mtd");
  37. rt = -1;
  38. goto close;
  39. }
  40. printf("erase %s sucess\n", argv[1]);
  41. close:
  42. close(dev_fd);
  43. exit:
  44. return rt;
  45. }


============================================
作者:yuanlulu
http://blog.csdn.net/yuanlulu
版权没有,但是转载请保留此段声明

============================================


<pre data-index="3"></pre>
<pre data-index="4"></pre>
<pre data-index="5"></pre>
<pre data-index="6"></pre>
<pre data-index="7"></pre>
<pre data-index="8"></pre>
<pre data-index="9"></pre>
<pre data-index="10"></pre>
<pre data-index="11"></pre>
<pre data-index="12"></pre>
<pre data-index="13"></pre>
<pre data-index="14"></pre>
<pre data-index="15"></pre>
<pre data-index="16"></pre>
<pre data-index="17"></pre>
<pre data-index="18"></pre>
<pre data-index="19"></pre>
<pre data-index="20"></pre>
<pre data-index="21"></pre>
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号