Skip to contentSkip to conversation

mtd: nand: Fix ecc in mxs_nand_spl onfi mode

PATCH New Michael Trimarchi 1 participant 2 messages Jul 8, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mtd: nand: Fix ecc in mxs_nand_spl onfi mode

We need to calculate the ecc parameters in a way that are the same in uboot and spl. The parameters are connected to the onfi computation. We need to assign all the value of chip in order to have same ecc strength parameters before calling

mxs_nand_set_geometry that calculate the ecc layout

/* use the legacy bch setting by default */
if ((!nand_info->use_minimum_ecc && mtd->oobsize < 1024) ||

     !(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0)) {
	dev_dbg(mtd->dev, "use legacy bch geometry\n");
	err = mxs_nand_legacy_calc_ecc_layout(geo, mtd);
	if (!err)
		return 0;
}
---
 drivers/mtd/nand/raw/mxs_nand_spl.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/mtd/nand/raw/mxs_nand_spl.c +6 -0
index 3daacbb330..683071c1cb 100644
@@ -139,6 +139,10 @@ static int mxs_flash_onfi_ident(struct mtd_info *mtd)
 	mtd->writesize = le32_to_cpu(p->byte_per_page);
 	mtd->erasesize = le32_to_cpu(p->pages_per_block) * mtd->writesize;
 	mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page);
+	if (p->ecc_bits != 0xff) {
+		chip->ecc_strength_ds = p->ecc_bits;
+		chip->ecc_step_ds = 512;
+	}
 	chip->chipsize = le32_to_cpu(p->blocks_per_lun);
 	chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count;
 	/* Calculate the address shift from the page size */
@@ -152,6 +156,8 @@ static int mxs_flash_onfi_ident(struct mtd_info *mtd)
 	debug("writesize=%d (>>%d)\n", mtd->writesize, chip->page_shift);
 	debug("oobsize=%d\n", mtd->oobsize);
 	debug("chipsize=%lld\n", chip->chipsize);
+	debug("ecc_strength_ds=%d\n", chip->ecc_strength_ds);
+	debug("ecc_step_ds = %d\n", chip->ecc_step_ds);
 
 	return 0;
 }
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 mtd: nand: mxs_nand_spl Fix loop exit condition

When size is 0 we need to stop the inner loop or we just waste time to load all the block of the eraseblock

---
 drivers/mtd/nand/raw/mxs_nand_spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/mxs_nand_spl.c +1 -1
index 683071c1cb..05886fa025 100644
@@ -263,7 +263,7 @@ int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
 	while (block <= lastblock && size > 0) {
 		if (!is_badblock(mtd, mtd->erasesize * block, 1)) {
 			/* Skip bad blocks */
-			while (page < nand_page_per_block) {
+			while (page < nand_page_per_block && size > 0) {
 				int curr_page = nand_page_per_block * block + page;
 
 				if (mxs_read_page_ecc(mtd, page_buf, curr_page) < 0) {
Signature · 1 line
2.34.1