Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indicate the progress of flashing for better user experience. #75

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good fix, but unrelated.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting that you just do left % N == 0 for some value of N to avoid printing that often, but I guess this works as well...

// 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