From patchwork Sat Jun 11 16:29:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 634089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rRl0C5hD1z9s2Q for ; Sun, 12 Jun 2016 02:30:51 +1000 (AEST) Received: from [127.0.0.1] (helo=ra.coresystems.de) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1bBlnH-0001qk-6g; Sat, 11 Jun 2016 18:29:55 +0200 Received: from 3.mo6.mail-out.ovh.net ([178.33.253.26]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1bBlmz-0001jG-HI for flashrom@flashrom.org; Sat, 11 Jun 2016 18:29:52 +0200 Received: from player693.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id 27FE7FFA04F for ; Sat, 11 Jun 2016 18:29:37 +0200 (CEST) Received: from hermes.ibm.com (LFbn-1-2234-107.w90-76.abo.wanadoo.fr [90.76.55.107]) (Authenticated sender: clg@kaod.org) by player693.ha.ovh.net (Postfix) with ESMTPSA id C69A144006D; Sat, 11 Jun 2016 18:29:32 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: flashrom@flashrom.org Date: Sat, 11 Jun 2016 18:29:04 +0200 Message-Id: <1465662544-5730-7-git-send-email-clg@kaod.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1465662544-5730-1-git-send-email-clg@kaod.org> References: <1465662544-5730-1-git-send-email-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 4355262317870222254 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekledrjeelgddutddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-Spam-Score: -2.1 (--) Subject: [flashrom] [PATCH 6/6] 4BA: Progress visualization for long read, writes and erases X-BeenThere: flashrom@flashrom.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: flashrom discussion and development mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: flashrom-bounces@flashrom.org Sender: "flashrom" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff From: Boris Baykov I've added progress visualization for read, erase and write operations. It's turned out that seeing progress is essential for reading and especially writing 32 MB of data via SPI. The operation can take more then 10 minutes on 15 MHz frequency of SPI. So, it's good to see its progress. I've added percents and slightly modified cli_output.c to send percents to screen only but not to logfile. Patched files ------------- cli_output.c + print() patched to skip strings which are starting from '\b' to prevent writing progress percents to logfile flash.h + added some definitions for progress visialization flashrom.c + added progress visualization for erase/write (essensial for 32MB+ chips) spi25.c + added progress visualization for read operation (essensial for 32MB+ chips) Signed-off-by: Boris Baykov , Russia, Jan 2014 [clg: ported from https://www.flashrom.org/pipermail/flashrom/2015-January/013203.html ] Signed-off-by: Cédric Le Goater --- cli_output.c | 3 ++- flash.h | 5 +++++ flashrom.c | 23 +++++++++++++++++++++++ spi25.c | 22 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/cli_output.c b/cli_output.c index feafbd2017b1..cb82fa1a64f6 100644 --- a/cli_output.c +++ b/cli_output.c @@ -90,7 +90,8 @@ int print(enum msglevel level, const char *fmt, ...) fflush(output_type); } #ifndef STANDALONE - if ((level <= verbose_logfile) && logfile) { + /* skip of msgs starting from '\b' added to skip progress percents */ + if ((level <= verbose_logfile) && logfile && (!fmt || fmt[0] != '\b')) { va_start(ap, fmt); ret = vfprintf(logfile, fmt, ap); va_end(ap); diff --git a/flash.h b/flash.h index 7f79387a9251..0b72439f5ec9 100644 --- a/flash.h +++ b/flash.h @@ -360,6 +360,11 @@ __attribute__((format(printf, 2, 3))); #define msg_pspew(...) print(MSG_SPEW, __VA_ARGS__) /* programmer debug spew */ #define msg_cspew(...) print(MSG_SPEW, __VA_ARGS__) /* chip debug spew */ +/* Read progress will be shown for reads more than 256KB */ +#define MIN_LENGTH_TO_SHOW_READ_PROGRESS 256 * 1024 +/* Read progress will be shown for erases and writes more than 64KB */ +#define MIN_LENGTH_TO_SHOW_ERASE_AND_WRITE_PROGRESS 64 * 1024 + /* layout.c */ int register_include_arg(char *name); int process_include_args(void); diff --git a/flashrom.c b/flashrom.c index 6a6f5b6f6af8..28b177b0199b 100644 --- a/flashrom.c +++ b/flashrom.c @@ -1527,6 +1527,17 @@ static int walk_eraseregions(struct flashctx *flash, int erasefunction, unsigned int start = 0; unsigned int len; struct block_eraser eraser = flash->chip->block_erasers[erasefunction]; + int show_progress = 0; + unsigned int percent_last, percent_current; + unsigned long size = flash->chip->total_size * 1024; + + /* progress visualizaion init */ + if(size >= MIN_LENGTH_TO_SHOW_ERASE_AND_WRITE_PROGRESS) { + msg_cinfo(" "); /* only this space will go to logfile but all strings with \b wont. */ + msg_cinfo("\b 0%%"); + percent_last = percent_current = 0; + show_progress = 1; /* enable progress visualizaion */ + } for (i = 0; i < NUM_ERASEREGIONS; i++) { /* count==0 for all automatically initialized array @@ -1544,8 +1555,20 @@ static int walk_eraseregions(struct flashctx *flash, int erasefunction, return 1; } start += len; + + if(show_progress) { + percent_current = (unsigned int) ((unsigned long long)start * 100 / size); + if(percent_current != percent_last) { + msg_cinfo("\b\b\b%2d%%", percent_current); + percent_last = percent_current; + } + } } } + + if(show_progress) + msg_cinfo("\b\b\b\b"); /* remove progress percents from the screen */ + msg_cdbg("\n"); return 0; } diff --git a/spi25.c b/spi25.c index b38c7444e873..93c4befacdc1 100644 --- a/spi25.c +++ b/spi25.c @@ -949,6 +949,16 @@ int spi_read_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, int rc = 0; unsigned int i, j, starthere, lenhere, toread; unsigned int page_size = flash->chip->page_size; + int show_progress = 0; + unsigned int percent_last, percent_current; + + /* progress visualizaion init */ + if(len >= MIN_LENGTH_TO_SHOW_READ_PROGRESS) { + msg_cinfo(" "); /* only this space will go to logfile but all strings with \b wont. */ + msg_cinfo("\b 0%%"); + percent_last = percent_current = 0; + show_progress = 1; /* enable progress visualizaion */ + } /* Warning: This loop has a very unusual condition and body. * The loop needs to go through each page with at least one affected @@ -976,8 +986,20 @@ int spi_read_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, } if (rc) break; + + if(show_progress) { + percent_current = (unsigned int) ((unsigned long long)(starthere + + lenhere - start) * 100 / len); + if(percent_current != percent_last) { + msg_cinfo("\b\b\b%2d%%", percent_current); + percent_last = percent_current; + } + } } + if(show_progress && !rc) + msg_cinfo("\b\b\b\b"); /* remove progress percents from the screen */ + return rc; }