mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 25/26] nand command: Print OOB information
Date: Fri,  6 Nov 2020 14:38:59 +0100	[thread overview]
Message-ID: <20201106133900.2656-26-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20201106133900.2656-1-s.hauer@pengutronix.de>

NAND mtd devices carry information how the OOB area is used. So far
there is no way to visualize it, so print it along with other NAND
informations.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/nand.c         |  5 +++
 drivers/mtd/core.c      | 81 +++++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/mtd.h |  2 +
 3 files changed, 88 insertions(+)

diff --git a/commands/nand.c b/commands/nand.c
index ed2864fb7b..67e43eba30 100644
--- a/commands/nand.c
+++ b/commands/nand.c
@@ -13,6 +13,7 @@
 #include <ioctl.h>
 #include <nand.h>
 #include <linux/mtd/mtd-abi.h>
+#include <linux/mtd/mtd.h>
 #include <fcntl.h>
 #include <libgen.h>
 
@@ -130,6 +131,8 @@ static int do_nand(int argc, char *argv[])
 		loff_t ofs;
 		int bad = 0;
 
+		printf("---- bad blocks ----\n");
+
 		for (ofs = 0; ofs < mtdinfo.size; ofs += mtdinfo.erasesize) {
 			if (ioctl(fd, MEMGETBADBLOCK, &ofs)) {
 				printf("Block at 0x%08llx is bad\n", ofs);
@@ -139,6 +142,8 @@ static int do_nand(int argc, char *argv[])
 
 		if (!bad)
 			printf("No bad blocks\n");
+
+		mtd_print_oob_info(mtdinfo.mtd);
 	}
 
 out:
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 22ed8d2d54..268c394ff7 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -1249,3 +1249,84 @@ void mtd_set_ecclayout(struct mtd_info *mtd, struct nand_ecclayout *ecclayout)
 	mtd_set_ooblayout(mtd, &mtd_ecclayout_wrapper_ops);
 }
 EXPORT_SYMBOL_GPL(mtd_set_ecclayout);
+
+void mtd_print_oob_info(struct mtd_info *mtd)
+{
+	struct mtd_oob_region region;
+	int ret, i = 0, j, rowsize;
+	unsigned char *oob;
+
+	if (!mtd->ooblayout)
+		return;
+
+	oob = malloc(mtd->oobsize);
+	if (!oob)
+		return;
+
+	memset(oob, ' ', mtd->oobsize);
+
+	printf("---- ECC regions ----\n");
+	while (1) {
+		ret = mtd->ooblayout->ecc(mtd, i, &region);
+		if (ret)
+			break;
+		printf("ecc:  offset: %4d length: %4d\n",
+		       region.offset, region.length);
+		i++;
+
+		for (j = 0; j < region.length; j++) {
+			unsigned char *p = oob + region.offset + j;
+
+			if (*p != ' ')
+				printf("oob offset %d already set to '%c'\n",
+				       region.offset + j, *p);
+			*p = 'e';
+		}
+	}
+
+	i = 0;
+
+	printf("---- free regions ----\n");
+	while (1) {
+		ret = mtd->ooblayout->free(mtd, i, &region);
+		if (ret)
+			break;
+
+		printf("free: offset: %4d length: %4d\n",
+		       region.offset, region.length);
+		i++;
+
+		for (j = 0; j < region.length; j++) {
+			unsigned char *p = oob + region.offset + j;
+
+			if (*p != ' ')
+				printf("oob offset %d already set to '%c'\n",
+				       region.offset + j, *p);
+			*p = 'f';
+		}
+	}
+
+	j = 0;
+	rowsize = 16;
+
+	printf("---- OOB area ----\n");
+	while (1) {
+		printf("%-4d", j);
+
+		for (i = 0; i < rowsize; i++) {
+			if (i + j >= mtd->oobsize)
+				break;
+			if (i == rowsize / 2)
+				printf(" ");
+			printf(" %c", oob[j + i]);
+		}
+
+		printf("\n");
+		j += rowsize;
+
+		if (j >= mtd->oobsize)
+			break;
+	}
+
+	free(oob);
+}
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 00a6a4f9c8..ee37dfd5cb 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -376,4 +376,6 @@ static inline int mtd_is_bitflip_or_eccerr(int err) {
 
 void mtd_set_ecclayout(struct mtd_info *mtd, struct nand_ecclayout *ecclayout);
 
+void mtd_print_oob_info(struct mtd_info *mtd);
+
 #endif /* __MTD_MTD_H__ */
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2020-11-06 13:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-06 13:38 [PATCH 00/26] Update nand layer to Linux-5.9 Sascha Hauer
2020-11-06 13:38 ` [PATCH 01/26] mtd: Drop asynchronous erase support Sascha Hauer
2020-11-06 13:38 ` [PATCH 02/26] mtd: nand: remove unused header file Sascha Hauer
2020-11-06 13:38 ` [PATCH 03/26] mtd: nand: drop unused erase_cmd hook Sascha Hauer
2020-11-06 13:38 ` [PATCH 04/26] mtd: nand: drop unused errstat hook Sascha Hauer
2020-11-06 13:38 ` [PATCH 05/26] mtd: nand: Pass struct nand_chip around Sascha Hauer
2020-11-06 13:38 ` [PATCH 06/26] mtd: Add underscore prefix to mtd hooks Sascha Hauer
2020-11-06 13:38 ` [PATCH 07/26] mtd: Use classdev->parent Sascha Hauer
2020-11-06 13:38 ` [PATCH 08/26] mtd: rename class_dev to dev Sascha Hauer
2020-11-06 13:38 ` [PATCH 09/26] mtd: rename master to parent Sascha Hauer
2020-11-06 13:38 ` [PATCH 10/26] lib: Add match_string() Sascha Hauer
2020-11-06 13:38 ` [PATCH 11/26] mtd: nand: move function hooks to struct nand_legacy Sascha Hauer
2020-11-06 13:38 ` [PATCH 12/26] mtd: Add ecc_step_size Sascha Hauer
2020-11-06 13:38 ` [PATCH 13/26] mtd: nand: omap_gpmc: Drop unused variable Sascha Hauer
2020-11-06 13:38 ` [PATCH 14/26] mtd: nand: omap_gpmc: Fix wrong length check Sascha Hauer
2020-11-06 13:38 ` [PATCH 15/26] mtd: nand: omap_gpmc: Add missing bch16 string Sascha Hauer
2020-11-06 13:38 ` [PATCH 16/26] mtd: nand: denali: Drop multichip support Sascha Hauer
2020-11-06 13:38 ` [PATCH 17/26] mtd: nand: marvell: Use nand_to_mtd() Sascha Hauer
2020-11-06 13:38 ` [PATCH 18/26] mtd: nand: gpmi: " Sascha Hauer
2020-11-06 13:38 ` [PATCH 19/26] mtd: nand: orion: " Sascha Hauer
2020-11-06 13:38 ` [PATCH 20/26] mtd: nand: Update to Linux-5.9 Sascha Hauer
2020-11-06 13:38 ` [PATCH 21/26] mtd: nand: denali: " Sascha Hauer
2020-11-06 13:38 ` [PATCH 22/26] mtd: nand: atmel: Return number of bitflips Sascha Hauer
2020-11-06 13:38 ` [PATCH 23/26] mtd: nand: atmel: drop dead code Sascha Hauer
2020-11-06 13:38 ` [PATCH 24/26] mtd: nand: atmel: Fix pmecc ecc settings Sascha Hauer
2020-11-06 13:38 ` Sascha Hauer [this message]
2020-11-06 13:39 ` [PATCH 26/26] nand command: Allow offsets with [kM] suffixes Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201106133900.2656-26-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox