[PATCH firmware-utils 3/3] otrx: support TRX from stdin when extracting
Rafał Miłecki
zajec5 at gmail.com
Sat Nov 27 07:31:04 PST 2021
From: Rafał Miłecki <rafal at milecki.pl>
It allows e.g.
dd if=firmware.chk skip=1 bs=58 | otrx extract - -1 kernel.bin
Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
src/otrx.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
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);
--
2.31.1
More information about the openwrt-devel
mailing list