Skip to content

Commit

Permalink
firehose: Add logs to show the progress of flashing
Browse files Browse the repository at this point in the history
Add logs to show the partition label currently being flashed and
amount of progress as a percentage of completion.

Signed-off-by: Viswanath Kraleti <quic_vkraleti@quicinc.com>
  • Loading branch information
quic-vkraleti committed Jun 17, 2024
1 parent cbd4618 commit 48c358f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion firehose.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down

0 comments on commit 48c358f

Please sign in to comment.