program: Skip entries without a valid filename

Follow the behavior of the other flash tools and skip partitions with no
filename, instead of filling them with zeros. This reduces the flash
time considerably for some set of xml files.

Also clean up firehose_program() as we no longer need to support calling
this function with an invalid fd.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Bjorn Andersson
2017-11-29 21:07:39 -08:00
parent febbbcc32e
commit 0251833b4d
2 changed files with 21 additions and 23 deletions

View File

@@ -332,16 +332,17 @@ static int firehose_program(int usbfd, struct program *program, int fd)
num_sectors = program->num_sectors;
if (fd >= 0) {
fstat(fd, &sb);
num_sectors = (sb.st_size + program->sector_size - 1) / program->sector_size;
ret = fstat(fd, &sb);
if (ret < 0)
err(1, "failed to stat \"%s\"\n", program->filename);
if (num_sectors > program->num_sectors) {
fprintf(stderr, "[PROGRAM] %s truncated to %d\n",
program->label,
program->num_sectors * program->sector_size);
num_sectors = program->num_sectors;
}
num_sectors = (sb.st_size + program->sector_size - 1) / program->sector_size;
if (num_sectors > program->num_sectors) {
fprintf(stderr, "[PROGRAM] %s truncated to %d\n",
program->label,
program->num_sectors * program->sector_size);
num_sectors = program->num_sectors;
}
buf = malloc(max_payload_size);
@@ -379,13 +380,9 @@ static int firehose_program(int usbfd, struct program *program, int fd)
while (left > 0) {
chunk_size = MIN(max_payload_size / program->sector_size, left);
if (fd >= 0) {
n = read(fd, buf, chunk_size * program->sector_size);
if (n < 0)
err(1, "failed to read");
} else {
n = 0;
}
n = read(fd, buf, chunk_size * program->sector_size);
if (n < 0)
err(1, "failed to read");
if (n < max_payload_size)
memset(buf + n, 0, max_payload_size - n);

View File

@@ -142,14 +142,15 @@ int program_execute(int usbfd, int (*apply)(int usbfd, struct program *program,
int fd;
for (program = programes; program; program = program->next) {
fd = -1;
if (program->filename) {
fd = open(program->filename, O_RDONLY);
if (fd < 0) {
printf("Unable to open %s...ignoring\n", program->filename);
continue;
}
if (!program->filename)
continue;
fd = open(program->filename, O_RDONLY);
if (fd < 0) {
printf("Unable to open %s...ignoring\n", program->filename);
continue;
}
ret = apply(usbfd, program, fd);
close(fd);