diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2020-11-06 09:32:54 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-11-10 08:42:29 +0100 |
commit | c03481bfcb29abfebf62e491a60caa0ebfb57a36 (patch) | |
tree | 9971af05edc84f71df5f64211c2a94c4e0dd2691 /drivers/mtd | |
parent | 3376ed2b01dc8d43d268a5778ddfe58e73622caf (diff) | |
download | barebox-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>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/core.c | 81 |
1 files changed, 81 insertions, 0 deletions
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, ®ion); + 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, ®ion); + 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); +} |