[PATCH 3/4] mtd: nand_msx: Implement ooblayout ops

Stefan Riedmueller s.riedmueller at phytec.de
Tue Mar 30 07:50:39 BST 2021


The default ooblayout ops do not work on nand_mxs devices and can lead
to an unresponsible system when doing a 'nand -i' on that device.

Thus implement the ooblayout ops for the nand_mxs driver separately.
Since writing the oob area is not supported simply return the whole oob
area as ecc.

Signed-off-by: Stefan Riedmueller <s.riedmueller at phytec.de>
---
 drivers/mtd/nand/nand_mxs.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/mtd/nand/nand_mxs.c b/drivers/mtd/nand/nand_mxs.c
index 96ae71364efb..285ae3c121b6 100644
--- a/drivers/mtd/nand/nand_mxs.c
+++ b/drivers/mtd/nand/nand_mxs.c
@@ -269,6 +269,33 @@ static void mxs_nand_return_dma_descs(struct mxs_nand_info *info)
 	info->desc_index = 0;
 }
 
+/*
+ * We don't support writing the oob area so simply return the whole oob
+ * as ECC.
+ */
+static int mxs_nand_ooblayout_ecc(struct mtd_info *mtd, int section,
+				  struct mtd_oob_region *oobregion)
+{
+	if (section)
+		return -ERANGE;
+
+	oobregion->offset = 0;
+	oobregion->length = mtd->oobsize;
+
+	return 0;
+}
+
+static int mxs_nand_ooblayout_free(struct mtd_info *mtd, int section,
+				   struct mtd_oob_region *oobregion)
+{
+	return -ERANGE;
+}
+
+static const struct mtd_ooblayout_ops mxs_nand_ooblayout_ops = {
+	.ecc = mxs_nand_ooblayout_ecc,
+	.free = mxs_nand_ooblayout_free,
+};
+
 static uint32_t mxs_nand_ecc_chunk_cnt(uint32_t page_data_size)
 {
 	return page_data_size / MXS_NAND_CHUNK_DATA_CHUNK_SIZE;
@@ -2218,6 +2245,8 @@ static int mxs_nand_probe(struct device_d *dev)
 	if (err)
 		goto err2;
 
+	mtd_set_ooblayout(mtd, &mxs_nand_ooblayout_ops);
+
 	mxs_nand_scan_bbt(chip);
 
 	err = add_mtd_nand_device(mtd, "nand");
-- 
2.25.1




More information about the barebox mailing list