From: Rafał Miłecki Date: Sat, 27 Nov 2021 15:31:04 +0000 (+0100) Subject: otrx: support TRX from stdin when extracting X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=56e8e19151743c923f48604c457850cf8eb52076;p=project%2Ffirmware-utils.git otrx: support TRX from stdin when extracting It allows e.g. dd if=firmware.chk skip=1 bs=58 | otrx extract - -1 kernel.bin Signed-off-by: Rafał Miłecki --- diff --git a/src/otrx.c b/src/otrx.c index 5ee310c..4ea19aa 100644 --- a/src/otrx.c +++ b/src/otrx.c @@ -558,7 +558,7 @@ static void otrx_extract_parse_options(int argc, char **argv) { } } -static int otrx_extract_copy(FILE *trx, size_t offset, size_t length, char *out_path) { +static int otrx_extract_copy(struct otrx_ctx *otrx, size_t length, char *out_path) { FILE *out; size_t bytes; uint8_t *buf; @@ -578,8 +578,7 @@ static int otrx_extract_copy(FILE *trx, size_t offset, size_t length, char *out_ goto err_close; } - fseek(trx, offset, SEEK_SET); - bytes = fread(buf, 1, length, trx); + bytes = fread(buf, 1, length, otrx->fp); if (bytes != length) { fprintf(stderr, "Couldn't read %zu B of data from %s\n", length, trx_path); err = -ENOMEM; @@ -631,9 +630,9 @@ static int otrx_extract(int argc, char **argv) { if (!part->offset && partition[part->idx]) printf("TRX doesn't contain partition %d, can't extract %s\n", part->idx + 1, partition[part->idx]); if (!part->offset || !partition[part->idx]) - continue; + otrx_skip(otrx.fp, part->length); else - otrx_extract_copy(otrx.fp, trx_offset + part->offset, part->length, partition[part->idx]); + otrx_extract_copy(&otrx, part->length, partition[part->idx]); } otrx_close(otrx.fp);