From patchwork Sat Sep 29 00:28:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 187915 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id BD5862C00CE for ; Sat, 29 Sep 2012 10:28:19 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3BFB7280F5; Sat, 29 Sep 2012 02:28:14 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 19ucCZ8LVNkI; Sat, 29 Sep 2012 02:28:14 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 50703280E3; Sat, 29 Sep 2012 02:28:12 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D809E280E3 for ; Sat, 29 Sep 2012 02:28:09 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h99jKUka5FQ3 for ; Sat, 29 Sep 2012 02:28:09 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-vb0-f74.google.com (mail-vb0-f74.google.com [209.85.212.74]) by theia.denx.de (Postfix) with ESMTPS id 0EA04280E2 for ; Sat, 29 Sep 2012 02:28:07 +0200 (CEST) Received: by vbis24 with SMTP id s24so411670vbi.3 for ; Fri, 28 Sep 2012 17:28:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=fYWm1DKqyBiIH5W2qieDW0/X4/If5IuQe+XiRAJyLHU=; b=BIVDWu4L8JL0h6OThjrdiha/1c9EOQrTK5LN0ynSQhihPN2f6bGXytHxtDRKbtXn2l L8zGR7pbu7lbdGfeva+H5HGHNjWq2oiWLjIfJPeODz3f4DWECB+ROoskp7dwMSNmeCQ2 23hKB4Fm5FDhVDf2jPetNsV0lEqVdxtp8sMnoZAVA2BohuoltBJSWEbb1J2KZ3qD5meO wC4/aM5iokvY9hS+XjKJ4Yv5fMe5mCjKPX8q3m94lJozWQeUXWwk7rrv/IZURvT4euVS yBBuTaL8BbTB43F6Fss4o4HzJmJcxCJh+Z1cUHb4ufYu2LbFIQHeWd7Uwm1joiThQZbf luHA== Received: by 10.101.23.13 with SMTP id a13mr1675603anj.18.1348878485940; Fri, 28 Sep 2012 17:28:05 -0700 (PDT) Received: from wpzn3.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id u42si2258027yhg.5.2012.09.28.17.28.05 (version=TLSv1/SSLv3 cipher=AES128-SHA); Fri, 28 Sep 2012 17:28:05 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by wpzn3.hot.corp.google.com (Postfix) with ESMTP id BFCDD100047; Fri, 28 Sep 2012 17:28:05 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 62286160897; Fri, 28 Sep 2012 17:28:05 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Fri, 28 Sep 2012 17:28:00 -0700 Message-Id: <1348878482-1730-1-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 X-Gm-Message-State: ALoCoQlx7VZsLj0+dEiZ76mJ/GNFGwDuaJXaeOlzvREfJByvMA4HEGrnPkFvYpJo/B4ydcKY7qUTGH2d2H9TgLkvHYaWkH5181uduoKc6pN8YkV0nDDbWTSUAVeFlQE5UbemUbP+YdjVs7+49FYZKTqe7SMc9XZ0Wr8u/glusR40SkTIbQIXH5HzhK5w3HQd4LB5JVTm3mL7 Cc: James Miller , Taylor Hutt Subject: [U-Boot] [PATCH 1/2] spi: Add progress percentage and write speed to `sf update` X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: James Miller 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 Signed-off-by: James Miller Signed-off-by: Taylor Hutt --- 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; }