From 590c28b378ff76022b910accfb8ff7c56095f4f8 Mon Sep 17 00:00:00 2001 From: david regan Date: Thu, 14 Aug 2025 11:04:55 -0700 Subject: cmd: nand: bug fix MTD_OOB_AUTO to MTD_OPS_AUTO_OOB bug fix MTD_OOB_AUTO to MTD_OPS_AUTO_OOB since MTD_OOB_AUTO does not exist Fixes: dfe64e2c8973 ("mtd: resync with Linux-3.7.1") Signed-off-by: david regan Signed-off-by: Michael Trimarchi --- cmd/nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/nand.c b/cmd/nand.c index 2f785deeb7f..e09e145bc2d 100644 --- a/cmd/nand.c +++ b/cmd/nand.c @@ -412,7 +412,7 @@ int do_nand_env_oob(struct cmd_tbl *cmdtp, int argc, char *const argv[]) } ops.datbuf = NULL; - ops.mode = MTD_OOB_AUTO; + ops.mode = MTD_OPS_AUTO_OOB; ops.ooboffs = 0; ops.ooblen = ENV_OFFSET_SIZE; ops.oobbuf = (void *) oob_buf; -- cgit v1.3.1 From 7ec4e91b2f3782530157766a9fc46d0eb27fae3a Mon Sep 17 00:00:00 2001 From: david regan Date: Thu, 14 Aug 2025 11:04:56 -0700 Subject: cmd: nand: more descriptive help info nand read/write raw change 'count' to 'pages' since count is ambiguous Signed-off-by: david regan Signed-off-by: Michael Trimarchi --- cmd/nand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/nand.c b/cmd/nand.c index e09e145bc2d..cb2a61a2e57 100644 --- a/cmd/nand.c +++ b/cmd/nand.c @@ -1026,8 +1026,8 @@ U_BOOT_LONGHELP(nand, "nand write - addr off|partition size\n" " read/write 'size' bytes starting at offset 'off'\n" " to/from memory address 'addr', skipping bad blocks.\n" - "nand read.raw - addr off|partition [count]\n" - "nand write.raw[.noverify] - addr off|partition [count]\n" + "nand read.raw - addr off|partition [pages]\n" + "nand write.raw[.noverify] - addr off|partition [pages]\n" " Use read.raw/write.raw to avoid ECC and access the flash as-is.\n" #ifdef CONFIG_CMD_NAND_TRIMFFS "nand write.trimffs - addr off|partition size\n" -- cgit v1.3.1 From b5ce63e1350f94b51986765e8bd56f45d16af650 Mon Sep 17 00:00:00 2001 From: david regan Date: Thu, 14 Aug 2025 11:04:57 -0700 Subject: cmd: nand: nand dump display update show characters with nand dump similar to md along with offset into NAND Signed-off-by: david regan Signed-off-by: Michael Trimarchi --- cmd/nand.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'cmd') diff --git a/cmd/nand.c b/cmd/nand.c index cb2a61a2e57..832e990108c 100644 --- a/cmd/nand.c +++ b/cmd/nand.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "legacy-mtd-utils.h" @@ -198,30 +199,18 @@ static int nand_dump(struct mtd_info *mtd, ulong off, int only_oob, ret = 1; goto free_all; } - printf("Page %08lx dump:\n", off); + printf("\nPage at offset %08lx dump:\n", off); if (!only_oob) { - i = mtd->writesize >> 4; + i = mtd->writesize; p = datbuf; - - while (i--) { - printf("\t%02x %02x %02x %02x %02x %02x %02x %02x" - " %02x %02x %02x %02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], - p[8], p[9], p[10], p[11], p[12], p[13], p[14], - p[15]); - p += 16; - } + print_buffer(off, p, 1, i, 16); } - puts("OOB:\n"); - i = mtd->oobsize >> 3; + puts("\nOOB:\n"); + i = mtd->oobsize; p = oobbuf; - while (i--) { - printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - p += 8; - } + print_buffer(0, p, 1, i, 8); free_all: free(oobbuf); -- cgit v1.3.1 From bb5d3a7a1c83cca588b5795630bf8fb3db950e5e Mon Sep 17 00:00:00 2001 From: david regan Date: Thu, 14 Aug 2025 11:04:58 -0700 Subject: cmd: nand: nand dump with ecc option option to show nand dump data ecc corrected as opposed to just raw Signed-off-by: david regan Signed-off-by: Michael Trimarchi --- cmd/nand.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'cmd') diff --git a/cmd/nand.c b/cmd/nand.c index 832e990108c..b5678b0a008 100644 --- a/cmd/nand.c +++ b/cmd/nand.c @@ -160,7 +160,7 @@ free_memory: } static int nand_dump(struct mtd_info *mtd, ulong off, int only_oob, - int repeat) + int ecc, int repeat) { int i; u_char *datbuf, *oobbuf, *p; @@ -192,12 +192,16 @@ static int nand_dump(struct mtd_info *mtd, ulong off, int only_oob, ops.oobbuf = oobbuf; ops.len = mtd->writesize; ops.ooblen = mtd->oobsize; - ops.mode = MTD_OPS_RAW; + if (ecc) + ops.mode = MTD_OPS_PLACE_OOB; + else + ops.mode = MTD_OPS_RAW; i = mtd_read_oob(mtd, addr, &ops); if (i < 0) { - printf("Error (%d) reading page %08lx\n", i, off); + printf("Error reading page at offset %08lx, %d %s\n", + off, i, i == -EUCLEAN ? "correctable" : + "uncorrectable, dumping raw data"); ret = 1; - goto free_all; } printf("\nPage at offset %08lx dump:\n", off); @@ -212,7 +216,6 @@ static int nand_dump(struct mtd_info *mtd, ulong off, int only_oob, p = oobbuf; print_buffer(0, p, 1, i, 8); -free_all: free(oobbuf); free_dat: free(datbuf); @@ -697,11 +700,19 @@ static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc, } if (strncmp(cmd, "dump", 4) == 0) { + int only_oob, ecc; + if (argc < 3) goto usage; + only_oob = !strcmp(&cmd[4], ".oob") || !strcmp(&cmd[4], ".ecc.oob") || + !strcmp(&cmd[4], ".oob.ecc"); + + ecc = !strcmp(&cmd[4], ".ecc") || !strcmp(&cmd[4], ".ecc.oob") || + !strcmp(&cmd[4], ".oob.ecc"); + off = (int)hextoul(argv[2], NULL); - ret = nand_dump(mtd, off, !strcmp(&cmd[4], ".oob"), repeat); + ret = nand_dump(mtd, off, only_oob, ecc, repeat); return ret == 0 ? 1 : 0; } @@ -1031,7 +1042,7 @@ U_BOOT_LONGHELP(nand, "nand erase.part [clean] partition - erase entire mtd partition'\n" "nand erase.chip [clean] - erase entire chip'\n" "nand bad - show bad blocks\n" - "nand dump[.oob] off - dump page\n" + "nand dump[.oob][.ecc] off - dump raw (default) or ecc corrected page at offset\n" #ifdef CONFIG_CMD_NAND_WATCH "nand watch - check an area for bitflips\n" "nand watch.part - check a partition for bitflips\n" -- cgit v1.3.1 From d246e70cf81d0a0d7cc49abd520c93df59d42e16 Mon Sep 17 00:00:00 2001 From: Miquel Raynal Date: Mon, 4 Aug 2025 11:21:37 +0200 Subject: cmd: mtd: Enable speed benchmarking Linux features a flash_speed speed test from the mtd-utils suite, U-Boot does not. Benchmarks are useful for speed improvement developments as well as troubleshooting or regression testing sometimes. Enable a benchmark option to enable this feature. Example of output on a Nuvoton platform: MA35D1> mtd read nor0 0x81000000 0 0x10000 Reading 65536 byte(s) at offset 0x00000000 MA35D1> mtd read.benchmark nor0 0x81000000 0 0x10000 Reading 65536 byte(s) at offset 0x00000000 Read speed: 3752kiB/s Signed-off-by: Miquel Raynal Signed-off-by: Michael Trimarchi --- cmd/mtd.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/mtd.c b/cmd/mtd.c index c25997cfb24..2520b89eed2 100644 --- a/cmd/mtd.c +++ b/cmd/mtd.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -466,8 +467,9 @@ static int mtd_special_write_oob(struct mtd_info *mtd, u64 off, static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - bool dump, read, raw, woob, write_empty_pages, has_pages = false; + bool dump, read, raw, woob, benchmark, write_empty_pages, has_pages = false; u64 start_off, off, len, remaining, default_len; + unsigned long bench_start, bench_end; struct mtd_oob_ops io_op = {}; uint user_addr = 0, npages; const char *cmd = argv[0]; @@ -490,6 +492,7 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, read = dump || !strncmp(cmd, "read", 4); raw = strstr(cmd, ".raw"); woob = strstr(cmd, ".oob"); + benchmark = strstr(cmd, ".benchmark"); write_empty_pages = !has_pages || strstr(cmd, ".dontskipff"); argc -= 2; @@ -559,6 +562,9 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, led_activity_blink(); + if (benchmark) + bench_start = timer_get_us(); + /* Loop over the pages to do the actual read/write */ while (remaining) { /* Skip the block if it is bad */ @@ -586,6 +592,13 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, io_op.oobbuf += io_op.oobretlen; } + if (benchmark && bench_start) { + bench_end = timer_get_us(); + printf("%s speed: %lukiB/s\n", + read ? "Read" : "Write", + ((io_op.len * 1000000) / (bench_end - bench_start)) / 1024); + } + led_activity_off(); if (!ret && dump) -- cgit v1.3.1