运行环境
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
中定义
- 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使能以后
- 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