Skip to content

Commit 8fa7283

Browse files
richard-bootlinmiquelraynal
authored andcommitted
mtd: rawnand: sunxi: do not count BBM bytes twice
BBM is already part of USER_DATA section, so we should not remove it twice This was working ok because we are on the safe size, advertising that there was 2 bytes less available than in reality. But we can't change old platforms, since it may lead to a different ECC strength, so, introduce a legacy flag for old platforms, and switch the new platforms to the correct count. Signed-off-by: Richard Genoud <richard.genoud@bootlin.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 848c139 commit 8fa7283

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

drivers/mtd/nand/raw/sunxi_nand.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(struct nand_chip *nand)
275275
* @has_ecc_block_512: If the ECC can handle 512B or only 1024B chuncks
276276
* @has_ecc_clk: If the controller needs an ECC clock.
277277
* @has_mbus_clk: If the controller needs a mbus clock.
278+
* @legacy_max_strength:If the maximize strength function was off by 2 bytes
279+
* NB: this should not be used in new controllers
278280
* @reg_io_data: I/O data register
279281
* @reg_ecc_err_cnt: ECC error counter register
280282
* @reg_user_data: User data register
@@ -304,6 +306,7 @@ struct sunxi_nfc_caps {
304306
bool has_ecc_block_512;
305307
bool has_ecc_clk;
306308
bool has_mbus_clk;
309+
bool legacy_max_strength;
307310
unsigned int reg_io_data;
308311
unsigned int reg_ecc_err_cnt;
309312
unsigned int reg_user_data;
@@ -1805,10 +1808,22 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
18051808
ecc->size = 1024;
18061809
nsectors = mtd->writesize / ecc->size;
18071810

1808-
/* Reserve 2 bytes for the BBM */
1809-
bytes = (mtd->oobsize - 2) / nsectors;
1811+
/*
1812+
* The 2 BBM bytes should not be removed from the grand total,
1813+
* because they are part of the USER_DATA_SZ.
1814+
* But we can't modify that for older platform since it may
1815+
* result in a stronger ECC at the end, and break the
1816+
* compatibility.
1817+
*/
1818+
if (nfc->caps->legacy_max_strength)
1819+
bytes = (mtd->oobsize - 2) / nsectors;
1820+
else
1821+
bytes = mtd->oobsize / nsectors;
18101822

1811-
/* 4 non-ECC bytes are added before each ECC bytes section */
1823+
/*
1824+
* USER_DATA_SZ non-ECC bytes are added before each ECC bytes
1825+
* section, they contain the 2 BBM bytes
1826+
*/
18121827
bytes -= USER_DATA_SZ;
18131828

18141829
/* and bytes has to be even. */
@@ -2373,6 +2388,7 @@ static const u8 sunxi_user_data_len_h6[] = {
23732388

23742389
static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = {
23752390
.has_ecc_block_512 = true,
2391+
.legacy_max_strength = true,
23762392
.reg_io_data = NFC_REG_A10_IO_DATA,
23772393
.reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT,
23782394
.reg_user_data = NFC_REG_A10_USER_DATA,
@@ -2394,6 +2410,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = {
23942410
static const struct sunxi_nfc_caps sunxi_nfc_a23_caps = {
23952411
.has_mdma = true,
23962412
.has_ecc_block_512 = true,
2413+
.legacy_max_strength = true,
23972414
.reg_io_data = NFC_REG_A23_IO_DATA,
23982415
.reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT,
23992416
.reg_user_data = NFC_REG_A10_USER_DATA,

0 commit comments

Comments
 (0)