From 48c358fc90e2e6f3183282299c4f6431084eb9cb Mon Sep 17 00:00:00 2001 From: Viswanath Kraleti Date: Wed, 12 Jun 2024 10:19:29 +0530 Subject: [PATCH] firehose: Add logs to show the progress of flashing Add logs to show the partition label currently being flashed and amount of progress as a percentage of completion. Signed-off-by: Viswanath Kraleti --- firehose.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/firehose.c b/firehose.c index 01ded57..91c08b5 100644 --- a/firehose.c +++ b/firehose.c @@ -317,9 +317,10 @@ static int firehose_erase(struct qdl_device *qdl, struct program *program) xml_setpropf(node, "num_partition_sectors", "%d", program->num_sectors); xml_setpropf(node, "start_sector", "%s", program->start_sector); + fprintf(stderr, "[ERASE] Please wait, erasing \"%s\" now...\n", program->label); ret = firehose_write(qdl, doc); if (ret < 0) { - fprintf(stderr, "[PROGRAM] failed to write program command\n"); + fprintf(stderr, "[ERASE] failed to write program command\n"); goto out; } @@ -344,6 +345,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int void *buf; time_t t0; time_t t; + time_t tn; int left; int ret; int n; @@ -384,6 +386,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int xml_setpropf(node, "last_sector", "%d", program->last_sector); } + fprintf(stderr, "[PROGRAM] Please wait, flashing \"%s\" now...\n", program->label); ret = firehose_write(qdl, doc); if (ret < 0) { fprintf(stderr, "[PROGRAM] failed to write program command\n"); @@ -400,7 +403,16 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int lseek(fd, (off_t) program->file_offset * program->sector_size, SEEK_SET); left = num_sectors; + tn = t0; while (left > 0) { + t = time(NULL); + // Update status every second + if (t - tn > 1) { + fprintf(stderr, "[PROGRAM] %d sectors remaining out of %d (%.2f%%)\r", + left, num_sectors, + (float) (num_sectors - left) / num_sectors * 100.0); + tn = t; + } chunk_size = MIN(max_payload_size / program->sector_size, left); n = read(fd, buf, chunk_size * program->sector_size);