最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】MTD oob test出错:mtd_oobtest: error: verify failed at XXXX

工作和技术 crifan 3147浏览 0评论

【现象】

实现了Linux kernel中的nand flash driver后,用mtd oob test去测试oob数据读写,出现错误:

# insmod mtd_oobtest.ko dev=3

=================================================
mtd_oobtest: MTD device: 3
mtd_oobtest: MTD device size 67108864, eraseblock size 524288, page size 4096, count of eraseblocks 128, pages per eraseblock 128, OOB size 128
mtd_oobtest: scanning for bad eraseblocks
mtd_oobtest: scanned 128 eraseblocks, 0 are bad
mtd_oobtest: test 1 of 5
mtd_oobtest: erasing whole device
mtd_oobtest: erased 128 eraseblocks
mtd_oobtest: writing OOBs of whole device
mtd_oobtest: written up to eraseblock 0
mtd_oobtest: written 128 eraseblocks
mtd_oobtest: verifying all eraseblocks
mtd_oobtest: error: verify failed at 0x0
mtd_oobtest: error: verify failed at 0x1000
mtd_oobtest: error: verify failed at 0x2000
mtd_oobtest: error: verify failed at 0x3000
mtd_oobtest: error: verify failed at 0x4000
mtd_oobtest: error: verify failed at 0x5000
mtd_oobtest: error: verify failed at 0x6000
mtd_oobtest: error: verify failed at 0x7000
。。。。。

mtd_oobtest: error: verify failed at 0x7e000
mtd_oobtest: error: verify failed at 0x7f000
mtd_oobtest: verified up to eraseblock 0
mtd_oobtest: error: verify failed at 0x80000
mtd_oobtest: error: verify failed at 0x81000
。。。

mtd_oobtest: error: verify failed at 0x3e7000
mtd_oobtest: error: verify failed at 0x3e8000
mtd_oobtest: error: too many errors
mtd_oobtest: error -1 occurred

【解决过程】

1.开始怀疑是数据没有写入进去,后来在mtd_oobtest.c中加入代码调试,发现数据写入是正确的。

2.后来,终于搞懂了,原来是nand_base.c中的,oob 的layout设置有误,

原先是:

static struct nand_ecclayout nand_oob_64 = {
.eccbytes = 32,
.eccpos = {
   32, 33, 34, 35, 36, 37, 38, 39,
   40, 41, 42, 43, 44, 45, 46, 47,
   48, 49, 50, 51, 52, 53, 54, 55,
   56, 57, 58, 59, 60, 61, 62, 63},
.oobfree = {
   {.offset = 2,
   .length = 30}}
};

static struct nand_ecclayout nand_oob_128 = {
.eccbytes = 64,
.eccpos = {
   64, 65, 66, 67, 68, 69, 70, 71,
   72, 73, 74, 75, 76, 77, 78, 79,
   80, 81, 82, 83, 84, 85, 86, 87,
   88, 89, 90, 91, 92, 93, 94, 95,
   96, 97, 98, 99, 100, 101, 102, 103,
   104, 105, 106, 107, 108, 109, 110, 111,
   112, 113, 114, 115, 116, 117, 118, 119,
   120, 121, 122, 123, 124, 125, 126, 127},
.oobfree = {
   {.offset = 2,
   .length = 30}}
};

应该改成:

static struct nand_ecclayout nand_oob_64 = {
.eccbytes = 32,
.eccpos = {
   32, 33, 34, 35, 36, 37, 38, 39,
   40, 41, 42, 43, 44, 45, 46, 47,
   48, 49, 50, 51, 52, 53, 54, 55,
   56, 57, 58, 59, 60, 61, 62, 63},
.oobfree = {
   {.offset = 2,
   .length = 22/* from 24-63 store HW BCH4 ECC if HW BCH4 ECC is enabled */}}
};

static struct nand_ecclayout nand_oob_128 = {
.eccbytes = 64,
.eccpos = {
   64, 65, 66, 67, 68, 69, 70, 71,
   72, 73, 74, 75, 76, 77, 78, 79,
   80, 81, 82, 83, 84, 85, 86, 87,
   88, 89, 90, 91, 92, 93, 94, 95,
   96, 97, 98, 99, 100, 101, 102, 103,
   104, 105, 106, 107, 108, 109, 110, 111,
   112, 113, 114, 115, 116, 117, 118, 119,
   120, 121, 122, 123, 124, 125, 126, 127},
.oobfree = {
   {.offset = 2,
   .length = 54/* from 56-127 store HW BCH4 ECC if HW BCH4 ECC is enabled */}}
};

因为我这里的特殊的HW 的BCH4 的ECC,oob区域:

对于2k pagesize的nand,占用了24到63;

对于4k pagesize的nand,占用了54到127;

所以,要改成对应的值,否则,还是像上面那样写成30和62的话,那oob空闲区域(oob中,除了开始的2个字节的用于判定是否坏块和ecc的大小之外)的最后8个字节,实际就是被HW BCH4的ecc占用了,

所以,准备好buffer后,每次去写入oob,再读出来的值,后面那8个字节都是不匹配的,所以oob test一直报错。像上面那样修改,留给足够的ECC的空间用于存放ecc的值之后,就解决问题了。

其他人如果遇到此类问题,也是根据你的具体情况去修改oob layout,也就可以了。

转载请注明:在路上 » 【已解决】MTD oob test出错:mtd_oobtest: error: verify failed at XXXX

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
79 queries in 0.215 seconds, using 22.12MB memory