fel: support FEL progress gauge via dialog utility

This patch adds some additional commands, and implements corresponding
progress callbacks that produce output for the 'dialog' utility:
http://invisible-island.net/dialog/dialog.html

The simple "*-with-gauge" just emits percentage numbers, line by line,
while "*-with-xgauge" outputs extended information to update the
dialog prompt. Both are meant for directly piping the output:
sunxi-fel write-with-gauge <...> | dialog --gauge "FEL upload" 6 70

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
This commit is contained in:
Bernhard Nortmann 2015-11-26 16:46:01 +01:00 committed by Siarhei Siamashka
parent 3626803f64
commit 6712eb84a0
3 changed files with 67 additions and 0 deletions

21
fel.c
View File

@ -1299,8 +1299,13 @@ int main(int argc, char **argv)
" read address length file Write memory contents into file\n"
" write address file Store file contents into memory\n"
" write-with-progress addr file \"write\" with progress bar\n"
" write-with-gauge addr file Output progress for \"dialog --gauge\"\n"
" write-with-xgauge addr file Extended gauge output (updates prompt)\n"
" multi[write] # addr file ... \"write-with-progress\" multiple files,\n"
" sharing a common progress status\n"
" multi[write]-with-gauge ... like their \"write-with-*\" counterpart,\n"
" multi[write]-with-xgauge ... but following the 'multi' syntax:\n"
" <#> addr file [addr file [...]]\n"
" ver[sion] Show BROM version\n"
" clear address length Clear memory\n"
" fill address length value Fill memory\n"
@ -1367,11 +1372,27 @@ int main(int argc, char **argv)
} else if (strcmp(argv[1], "write-with-progress") == 0 && argc > 3) {
skip += 2 * file_upload(handle, 1, argc - 2, argv + 2,
progress_bar);
} else if (strcmp(argv[1], "write-with-gauge") == 0 && argc > 3) {
skip += 2 * file_upload(handle, 1, argc - 2, argv + 2,
progress_gauge);
} else if (strcmp(argv[1], "write-with-xgauge") == 0 && argc > 3) {
skip += 2 * file_upload(handle, 1, argc - 2, argv + 2,
progress_gauge_xxx);
} else if ((strcmp(argv[1], "multiwrite") == 0 ||
strcmp(argv[1], "multi") == 0) && argc > 4) {
size_t count = strtoul(argv[2], NULL, 0); /* file count */
skip = 2 + 2 * file_upload(handle, count, argc - 3,
argv + 3, progress_bar);
} else if ((strcmp(argv[1], "multiwrite-with-gauge") == 0 ||
strcmp(argv[1], "multi-with-gauge") == 0) && argc > 4) {
size_t count = strtoul(argv[2], NULL, 0); /* file count */
skip = 2 + 2 * file_upload(handle, count, argc - 3,
argv + 3, progress_gauge);
} else if ((strcmp(argv[1], "multiwrite-with-xgauge") == 0 ||
strcmp(argv[1], "multi-with-xgauge") == 0) && argc > 4) {
size_t count = strtoul(argv[2], NULL, 0); /* file count */
skip = 2 + 2 * file_upload(handle, count, argc - 3,
argv + 3, progress_gauge_xxx);
} else if (strcmp(argv[1], "read") == 0 && argc > 4) {
size_t size = strtoul(argv[3], NULL, 0);
void *buf = malloc(size);

View File

@ -119,3 +119,47 @@ void progress_bar(size_t total, size_t done)
fflush(stdout);
}
/*
* Progress callback that emits percentage numbers, each on a separate line.
* The output is suitable for piping it into "dialog --gauge".
*
* sunxi-fel multiwrite-with-gauge <...> \
* | dialog --title "FEL upload progress" \
* --gauge "" 5 70
*/
void progress_gauge(size_t total, size_t done)
{
if (total > 0) {
printf("%.0f\n", (float)done / total * 100);
fflush(stdout);
}
}
/*
* A more sophisticated version of progress_gauge() that also updates the
* prompt (caption) with additional information. This uses a feature of
* the dialog utility that parses "XXX" delimiters - see 'man dialog'.
*
* sunxi-fel multiwrite-with-xgauge <...> \
* | dialog --title "FEL upload progress" \
* --backtitle "Please wait..." \
* --gauge "" 6 70
*/
void progress_gauge_xxx(size_t total, size_t done)
{
if (total > 0) {
double speed = rate(done, progress_elapsed());
double eta = estimate(total - done, speed);
printf("XXX\n");
printf("%.0f\n", (float)done / total * 100);
if (done < total)
printf("%zu of %zu, %.1f kB/s, ETA %s\n",
done, total, kilo(speed), format_ETA(eta));
else
printf("Done: %.1f kB, at %.1f kB/s\n",
kilo(done), kilo(speed));
printf("XXX\n");
fflush(stdout);
}
}

View File

@ -35,5 +35,7 @@ void progress_update(size_t bytes_done);
/* progress callback implementations for various display styles */
void progress_bar(size_t total, size_t done);
void progress_gauge(size_t total, size_t done);
void progress_gauge_xxx(size_t total, size_t done);
#endif /* _SUNXI_TOOLS_PROGRESS_H */