summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-11-06 09:32:54 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-11-10 08:42:29 +0100
commitc03481bfcb29abfebf62e491a60caa0ebfb57a36 (patch)
tree9971af05edc84f71df5f64211c2a94c4e0dd2691
parent3376ed2b01dc8d43d268a5778ddfe58e73622caf (diff)
downloadbarebox-c03481bfcb29abfebf62e491a60caa0ebfb57a36.tar.gz
barebox-c03481bfcb29abfebf62e491a60caa0ebfb57a36.tar.xz
nand command: Print OOB information
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>
-rw-r--r--commands/nand.c5
-rw-r--r--drivers/mtd/core.c81
-rw-r--r--include/linux/mtd/mtd.h2
3 files changed, 88 insertions, 0 deletions
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 0e77bb69ec..1b1ed53a61 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -1251,3 +1251,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__ */