summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2025-08-04 11:21:37 +0200
committerMichael Trimarchi <michael@amarulasolutions.com>2025-08-23 16:37:22 +0200
commitd246e70cf81d0a0d7cc49abd520c93df59d42e16 (patch)
treee1c287aa1ab2569f979f46a6a7e280cdada8a6d3
parentbb5d3a7a1c83cca588b5795630bf8fb3db950e5e (diff)
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 <miquel.raynal@bootlin.com> Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
-rw-r--r--cmd/mtd.c15
1 files changed, 14 insertions, 1 deletions
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 <malloc.h>
#include <mapmem.h>
#include <mtd.h>
+#include <time.h>
#include <dm/devres.h>
#include <linux/err.h>
@@ -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)