[U-Boot-Users] [PATCH] Add flash programming counter]

Jerry Van Baren gerald.vanbaren at ge.com
Thu Mar 6 20:35:21 CET 2008


Michael Schwingen wrote:
> Wolfgang Denk wrote:
>> Please let's stay terse. Printing a dot is a single character on  the
>> console.  I dislike funny stuff which requires output of non-printing
>> characters or (weven worse!) terminal specific escape sequences.
>>   
> Backspace or CR without LF should work on all terminals, no?
> 
> No matter how it is implemented, I am strongly in favor of *some* kind 
> of progress output.
> 
> If it is possible to estimate how long the operation will take, this 
> would be a big plus IMHO (which precludes the simple dots).
> 
> cu
> Michael

Hi Michael, Stefan, Wolfgang,

I understand where you are coming from and like countdowns a lot when 
driving the system from a terminal.

The dark side of countdowns with \r characters is if you capture it in a 
log file.  It isn't impossibly bad, but you end up with a lot of crap in 
your log file.

The dark side of dots, as you point out, is that you don't know how many 
dots are suppose to print, at least the first couple of times you do it.

Here is a thought, what about printing a bar and then print the dots. 
How sophisticated is our printf() formatting capabilities?  Hmmm.  How 
about something like this (I think the?

#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
         int k;
         int cnt;

         if(sscanf(argv[1], "%d", &cnt) != 1) {
                 fprintf(stderr, "sscanf() failed\n");
                 return 0;
         } else {

                 printf("%*c\r", (cnt + (1 << 14) - 1) / (1 << 14), '|');
                 fflush(stdout);

                 for(k = 0; k < cnt; k++) {
                         if ((k % (1 << 14)) == 0) {
                                 sleep(1);
                                 putchar('.');
                                 fflush(stdout);
                         }
                 }
                 printf("\n");
         }
         return 0;
}

Example use:

After three dots are printed:
./dots 491520
...                          |

At the end:
 > ./dots 491520
..............................


Note that, if our printf() doesn't understand the '*' modifier, it could 
still be done with a static string that is at least as long as the 
expected length.  That would be much less desirable, however, because it 
is hard to guess what the maximum length string should be.

The above also is a little iffy with line wrapping if you have more than 
79 dots.

Using '\r' rather than '\n' on the progress bar is on the iffy side.  It 
looks cool on a video terminal, but '\n' is a safer choice.  It also has 
less problems with line wrapping (ugly, but still understandable). 
Substituting
                 printf("%*c\n", (cnt + (1 << 14) - 1) / (1 << 14), '|');
looks like:
 > ./dots 491520
                              |
..............................

Best regards,
gvb




More information about the U-Boot mailing list