diff --git a/fel.c b/fel.c index 36fb544..cdb34c7 100644 --- a/fel.c +++ b/fel.c @@ -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); diff --git a/progress.c b/progress.c index 05d8f8b..47ea893 100644 --- a/progress.c +++ b/progress.c @@ -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); + } +} diff --git a/progress.h b/progress.h index b072cc0..b5c97aa 100644 --- a/progress.h +++ b/progress.h @@ -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 */