Linux nandflash的mtd字符驱动bch调试分析(2)

运行环境

CPU:君正M300

运行操作系统:Linux5.10.180

调试环境:Ubuntu18.04.6

调试模块:nandflash

上篇分析道修改为上述代码后ecc可正常使用,但是读的时候会由打印sfcnand_do_read error, ret = -77的错误,

M300的NandFlash是spi flash,相关datasheet的一些指令操作在

kernel/module_drivers/drivers/mtd/devices/ingenic_sfc_v2/spinand_cmd.h

中定义

  1. datasheet说明了硬件ECC默认打开,如果要关闭,按手册如下说明操作

To enable/disable ECC, perform the following command sequence:
• Issue the SET FEATURES command (1FH) to set the feature bit ECC_EN:
1. To enable ECC, Set ECC_EN to 1.
2. To disable ECC, Clear ECC_EN to 0

硬件ECC使能以后

  1. 800H is reserved for initial bad block mark.
    2. When Internal ECC is enabled, user cannot program the Address 840H~87FH, but user can read the Address
    840H~87FH.
    3. When Internal ECC is disabled, the whole page area is open for user. And we recommend the user to provide external
    ECC protection 

查看GD5F4GQ6的datasheet,硬件已经上电默认打开了ECC校验,无需软件进行BCH ECC计算后写oob的操作,如需软件操作,需要关闭硬件ECC,在没有关闭硬件的ECC时,程序写入数据和软件BCH ECC到oob后,去读数据或ECC的时候内核会有-77的错误,经过调试,在内核代码中关闭硬件ECC后,再做相同的操作不会有-77的错误

返回-77的原因是为读完数据后会读flash的状态

ingenic_sfcnand_read

        sfcnand_do_read

                ret = ops->get_feature(flash, GET_ECC_STATUS);

get_feature就是nand_common_get_feature

nand_info->ops->get_feature = nand_common_get_feature

nand_common_get_feature的调用就和ingenic_sfc_nand_get_feature一样,读addr=C0的寄存器,通过打印输出status值为0x20,对照datasheet的表12-1可知具体含义

ops->deal_ecc_status(flash, device_id, ecc_status);

deal_ecc_status就是gd_nand.c里面的deal_ecc_status,这个函数就是去解析表12-3,这里解析到错误了就返回了-77

只要关闭硬件ECC功能就可以正常操作了,不会返回错误,下文讲解如何关闭硬件ECC

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT砖员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值