public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] spi: Add progress percentage and write speed to `sf update`
@ 2012-09-29  0:28 Simon Glass
  2012-09-29  0:28 ` [U-Boot] [PATCH 2/2] spi: Add SPI flash test Simon Glass
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Simon Glass @ 2012-09-29  0:28 UTC (permalink / raw)
  To: u-boot

From: James Miller <jamesmiller@chromium.org>

Output a progress update only at most 10 times per second, to avoid
saturating (and waiting on) the console. Make the summary line
to fit on a single line. Make sure that cursor sits at the end of
each update line instead of the beginning.

Sample output:

SF: Detected W25Q32 with page size 4 KiB, total 4 MiB
Update SPI
1331200 bytes written, 2863104 bytes skipped in 21.912s, speed 199728 B/s

time: 21.919 seconds, 21919 ticks
Skipping verify

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: James Miller <jamesmiller@chromium.org>
Signed-off-by: Taylor Hutt <thutt@chromium.org>
---
 common/cmd_sf.c |   41 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 5ac1d0c..e22a45e 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -67,6 +67,23 @@ static int sf_parse_len_arg(char *arg, ulong *len)
 	return 1;
 }
 
+/**
+ * This function takes a byte length and a delta unit of time to compute the
+ * approximate bytes per second
+ *
+ * @param len		amount of bytes currently processed
+ * @param start_ms	start time of processing in ms
+ * @return bytes per second if OK, 0 on error
+ */
+static const ulong bytes_per_second(unsigned int len, ulong start_ms)
+{
+	/* less accurate but avoids overflow */
+	if (len >= ((unsigned int) -1) / 1024)
+		return len / (max(get_timer(start_ms) / 1024, 1));
+	else
+		return 1024 * len / max(get_timer(start_ms), 1);
+}
+
 static int do_spi_flash_probe(int argc, char * const argv[])
 {
 	unsigned int bus = CONFIG_SF_DEFAULT_BUS;
@@ -167,11 +184,26 @@ static int spi_flash_update(struct spi_flash *flash, u32 offset,
 	const char *end = buf + len;
 	size_t todo;		/* number of bytes to do in this pass */
 	size_t skipped = 0;	/* statistics */
+	const ulong start_time = get_timer(0);
+	size_t scale = 1;
+	const char *start_buf = buf;
+	ulong delta;
 
+	if (end - buf >= 200)
+		scale = (end - buf) / 100;
 	cmp_buf = malloc(flash->sector_size);
 	if (cmp_buf) {
+		ulong last_update = get_timer(0);
+
 		for (; buf < end && !err_oper; buf += todo, offset += todo) {
 			todo = min(end - buf, flash->sector_size);
+			if (get_timer(last_update) > 100) {
+				printf("   \rUpdating, %zu%% %lu B/s",
+					100 - (end - buf) / scale,
+					bytes_per_second(buf - start_buf,
+							 start_time));
+				last_update = get_timer(0);
+			}
 			err_oper = spi_flash_update_block(flash, offset, todo,
 					buf, cmp_buf, &skipped);
 		}
@@ -179,12 +211,17 @@ static int spi_flash_update(struct spi_flash *flash, u32 offset,
 		err_oper = "malloc";
 	}
 	free(cmp_buf);
+	putc('\r');
 	if (err_oper) {
 		printf("SPI flash failed in %s step\n", err_oper);
 		return 1;
 	}
-	printf("%zu bytes written, %zu bytes skipped\n", len - skipped,
-	       skipped);
+
+	delta = get_timer(start_time);
+	printf("%zu bytes written, %zu bytes skipped", len - skipped,
+		skipped);
+	printf(" in %ld.%lds, speed %ld B/s\n",
+		delta / 1000, delta % 1000, bytes_per_second(len, start_time));
 
 	return 0;
 }
-- 
1.7.7.3

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2012-12-21 19:52 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-29  0:28 [U-Boot] [PATCH 1/2] spi: Add progress percentage and write speed to `sf update` Simon Glass
2012-09-29  0:28 ` [U-Boot] [PATCH 2/2] spi: Add SPI flash test Simon Glass
2012-10-01 17:32   ` Tom Rini
2012-10-08 23:00     ` Simon Glass
2012-10-08 23:03       ` Tom Rini
2012-12-19 23:12   ` Wolfgang Denk
2012-12-19 20:43 ` [U-Boot] [U-Boot, 1/2] spi: Add progress percentage and write speed to `sf update` Tom Rini
2012-12-19 20:46   ` Simon Glass
2012-12-19 20:59     ` Tom Rini
2012-12-19 22:59       ` Tom Rini
2012-12-19 23:14         ` Wolfgang Denk
2012-12-20  1:03           ` Tom Rini
2012-12-20  1:18             ` Simon Glass
2012-12-20 15:04               ` Tom Rini
2012-12-21  8:46               ` Jagan Teki
2012-12-21 18:21                 ` Simon Glass
2012-12-21 19:52                   ` Wolfgang Denk
2012-12-19 23:10 ` [U-Boot] [PATCH " Wolfgang Denk
2012-12-19 23:20   ` Simon Glass
2012-12-19 23:42     ` Scott Wood
2012-12-20  6:20       ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox