×
单片机 > 单片机程序设计 > 详情

S5PV210 nand 4bit ecc笔记与AM335x的ECC

发布时间:2021-04-22 发布时间:
|

首先假设flash芯片页大小为2K + 64B的格式。

S5PV210
根据User Manual的4.3.7 4-BIT ECC PROGRAMMING GUIDE (ENCODING)
得知4bitecc的编码步骤为:
1. 写数据之前,设置Msglength(NCONF【25】)设为512,InitMECC(NFCONT[5])为1,MainECCLock (NFCONT[7]) 清零,解锁ECC;
2. 写数据时,每写512B,NFMECC0 and NFMECC1产生ECC code(7字节),当写完一页数据(我的nand页大小为2K)时,将ECC写入OOB(28字节)。

解码:


懒得写了,自己看代码吧,和8bit ecc的区别只是用的寄存器和ecc bytes大小不一样而已。

AM335x的ECC:
AM335x的ECC有2种:Hamming code(1bit ecc)和BCH(4bit ~ 16bitecc)
Hamming code针对页大于512byte的8bit或16bit位宽的nand
BCH提供4bit 、8bit、16bit的ecc。

一、Hamming code
根据7.1.3.3.12.3.1.1 ECC Result Register and ECC Computation Accumulation Size
1bit ecc:
根据数据流大小分2种,第一种每次读写256字节,第二种每次读写512字节,推荐用第二种。
每256字节产生3字节ecc code(实际22bit),2K页需要3x8=24字节ecc。
或者:每512字节产生3字节ecc code(实际24bit),2K页需要3x4=12字节ecc(明显优于第一种)。
存储在ECC[1-8]RESULTSIZE。

256字节:
具体来说,每256字节产生P1oP1eP2oP2eP4oP4eP8oP8eP16oP16e ~P1024oP1024e,总共22bit的ecc code。
其中,sixcolumn parity bits (P1o-P2o-P4o for odd parities, and P1e-P2e-P4e for even parities) and sixteen row
parity bits (P8o-P16o-P32o--P1024o for odd parities, and P8e-P16e-P32e--P1024e for even parities).
意思是6bit用于列的奇校验码,16bit用于行的奇校验码。
2^10 = 1024,所以P8o-P16o-P32o--P1024o 需要(10 - 2) = 8bit存储,P8e-P16e-P32e--P1024e也需要8bit存储

512字节:
对于512bytes的数据流,会产生24bit(3字节)的ecc校验码:
Figure 7-34 shows ECC computation for a 512-byte data stream (read or write). The result includes six
column parity bits (P1o-P2o-P4o for odd parities, and P1e-P2e-P4e for even parities) and eighteen row
parity bits (P8o-P16o-P32o--P1024o- - P2048o for odd parities, and P8e-P16e-P32e--P1024e- P2048e for
even parities).

二、BCH

The spare area is assumed to be large enough to hold the BCH ECC, that is, to have at least a
message of 13 bytes available per 512-byte sector of data. The zone of unused spare area by the
ECC may or may not be protected by the same ECC scheme, by extending the BCH message beyond
512 bytes (maximum codeword is 1023-byte long, ECC included, which leaves a lot of space to cover
some spares bytes).

512字节至少产生13字节的ecc(4bit ecc)。
根据7.1.3.3.12.3.2.2 Memory-Mapping of the BCH Codeword

BCH encoding considers a block of data to protect as a polynomial message M(x). In our standard case,
512 bytes of data (that is, 2 bits = 4096 bits) are seen as a polynomial of degree 2 - 1 = 4095, with
parameters ranging from M0 to M4095. For 512 bytes of data, 52 bits are required for 4-bit error
correction, and 104 bits are required for 8-bit error correction and 207 bits are required for 16-bit error
correction. The ECC is a remainder polynomial R(x) of degree 103 (or 51, depending on the selected
mode).

4bit ecc:
每512字节产生7字节ecc code,但是必须am335的硬件ecc模块ELM要求ecc bytes必须是偶数,所以7+1=8,2K页需要(7+1)x4=32字节。

8bit ecc:
每512字节产生13字节ecc code,2K页需要(13+1)x4=56字节。

16bit ecc:

和BCH8类似,占用更多oob空间。一般用在MLC上。
实际上BCH16这里我也没弄明白,懒得看代码了


总结
针对我的2K页的nand,OOB为64字节。

对于S5PV210,yaffs2分区可以采用4bitecc方案,因为只需要28字节,加上yaffs2的tag的28字节,2 + 28 + 28 = 58bytes <64Bytes。

对于AM335x,yaffs2分区只若用1bitecc,并且最好选择512字节流方式,每页只需要12字节,加上yaffs2的tag的28字节,2 + 12 + 28= 42bytes <64Bytes。 若使用4bitecc,则每2K页需要32字节,2+32+28=62Bytes < 64Bytes。故AM335x也可以采用4bitecc方案。

或者4bitecc方案,2 + 32 + 28= 62bytes <64Bytes

当然,使用软件ecc也是可以的,基本不许要花时间调试。补充一下软件ecc的oob布局:默认是每256字节产生3字节ecc code,u-boot中的软件ecc默认布局如下:

/* Define default oob placement schemes for large and small page devices */
static struct nand_ecclayout nand_oob_8 = {
.eccbytes = 3,
.eccpos = {0, 1, 2},
.oobfree = {
{.offset = 3,
.length = 2},
{.offset = 6,
.length = 2} }
};

static struct nand_ecclayout nand_oob_16 = {
.eccbytes = 6,
.eccpos = {0, 1, 2, 3, 6, 7},
.oobfree = {
{.offset = 8,
.length = 8} }
};

static struct nand_ecclayout nand_oob_64 = {
.eccbytes = 24,
.eccpos = {
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 = 38} }
};

static struct nand_ecclayout nand_oob_128 = {
.eccbytes = 48,
.eccpos = {
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 = 78} }
};


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
C8051F020的UART