[flashrom] [PATCH 6/10] 4BA: Progress visualization for long read, writes and erases

Boris Baykov dev at borisbaykov.com
Sun Jan 11 00:29:34 CET 2015


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 <dev at borisbaykov.com>, Russia, Jan 2014
---
diff -U 5 -N ./flashrom/cli_output.c ./flashrom-1868-4ba-6/cli_output.c
--- ./flashrom/cli_output.c     2015-01-11 01:55:15.000000000 +0300
+++ ./flashrom-1868-4ba-6/cli_output.c  2015-01-08 15:27:14.000000000 +0300
@@ -88,11 +88,12 @@
                 * time-critical operations. Don't slow them down by flushing. */
                if (level != MSG_SPEW)
                        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);
                if (level != MSG_SPEW)
                        fflush(logfile);
diff -U 5 -N ./flashrom/flash.h ./flashrom-1868-4ba-6/flash.h
--- ./flashrom/flash.h  2015-01-11 01:55:15.000000000 +0300
+++ ./flashrom-1868-4ba-6/flash.h       2015-01-10 19:00:34.000000000 +0300
@@ -355,10 +355,15 @@
 #define msg_cdbg2(...) print(MSG_DEBUG2, __VA_ARGS__)  /* chip debug2 */
 #define msg_gspew(...) print(MSG_SPEW, __VA_ARGS__)    /* general debug spew  */
 #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);
 int read_romlayout(const char *name);
 int normalize_romentries(const struct flashctx *flash);
diff -U 5 -N ./flashrom/flashrom.c ./flashrom-1868-4ba-6/flashrom.c
--- ./flashrom/flashrom.c       2015-01-11 01:55:15.000000000 +0300
+++ ./flashrom-1868-4ba-6/flashrom.c    2015-01-10 18:48:28.000000000 +0300
@@ -1460,10 +1460,21 @@
 {
        int i, j;
        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
                 * members so the loop below won't be executed for them.
                 */
@@ -1477,12 +1488,24 @@
                        if (do_something(flash, start, len, param1, param2,
                                         eraser.block_erase)) {
                                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;
 }
 
 static int check_block_eraser(const struct flashctx *flash, int k, int log)
diff -U 5 -N ./flashrom/spi25.c ./flashrom-1868-4ba-6/spi25.c
--- ./flashrom/spi25.c  2015-01-11 01:55:15.000000000 +0300
+++ ./flashrom-1868-4ba-6/spi25.c       2015-01-10 18:50:25.000000000 +0300
@@ -947,10 +947,20 @@
                     unsigned int len, unsigned int chunksize)
 {
        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
         * byte. The lowest page number is (start / page_size) since that
         * division rounds down. The highest page number we want is the page
@@ -974,12 +984,24 @@
                        if (rc)
                                break;
                }
                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;
 }
 
 /*
  * Write a part of the flash chip.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flashrom-r1868-4ba-part-6.patch.tar.bz2
Type: application/octet-stream
Size: 2340 bytes
Desc: not available
URL: <http://www.flashrom.org/pipermail/flashrom/attachments/20150111/55e71cf3/attachment.obj>


More information about the flashrom mailing list