diff options
author | Yousong Zhou <yszhou4tech@gmail.com> | 2016-07-09 20:15:57 +0800 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2016-07-11 13:26:33 +0200 |
commit | d06b68fe83ebb969baa64335779045d80bc41f89 (patch) | |
tree | 42d0c2dbe3c2c9e0962fc1b044713935a4efbeb1 | |
parent | 31e5ed4152c4aa826641b2db6b4245a03dd553b5 (diff) | |
download | upstream-d06b68fe83ebb969baa64335779045d80bc41f89.tar.gz upstream-d06b68fe83ebb969baa64335779045d80bc41f89.tar.bz2 upstream-d06b68fe83ebb969baa64335779045d80bc41f89.zip |
tools: padjffs2: add option to output padding data to stdout
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
-rw-r--r-- | tools/padjffs2/src/padjffs2.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/tools/padjffs2/src/padjffs2.c b/tools/padjffs2/src/padjffs2.c index 59c7625dc4..6308292431 100644 --- a/tools/padjffs2/src/padjffs2.c +++ b/tools/padjffs2/src/padjffs2.c @@ -15,6 +15,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <stdbool.h> #include <sys/types.h> #include <sys/stat.h> @@ -25,6 +26,7 @@ static unsigned char jffs2_pad_be[] = "\x19\x85\x20\x04\x04\x00\x00\x00\xc4\x94\ static unsigned char jffs2_pad_le[] = "\x85\x19\x04\x20\x00\x00\x00\x04\xa8\xfb\xa0\xb4"; static unsigned char *pad = eof_mark; static int pad_len = sizeof(eof_mark); +static bool pad_to_stdout = false; #define ERR(fmt, ...) do { \ fflush(0); \ @@ -46,6 +48,7 @@ static int pad_image(char *name, uint32_t pad_mask) { char *buf; int fd; + int outfd; ssize_t in_len; ssize_t out_len; int ret = -1; @@ -66,6 +69,11 @@ static int pad_image(char *name, uint32_t pad_mask) if (in_len < 0) goto close; + if (!pad_to_stdout) + outfd = fd; + else + outfd = STDOUT_FILENO; + memset(buf, '\xff', BUF_SIZE); in_len += xtra_offset; @@ -90,7 +98,7 @@ static int pad_image(char *name, uint32_t pad_mask) pad_mask &= ~mask; } - printf("padding image to %08x\n", (unsigned int) in_len - xtra_offset); + fprintf(stderr, "padding image to %08x\n", (unsigned int) in_len - xtra_offset); while (out_len < in_len) { ssize_t len; @@ -99,7 +107,7 @@ static int pad_image(char *name, uint32_t pad_mask) if (len > BUF_SIZE) len = BUF_SIZE; - t = write(fd, buf, len); + t = write(outfd, buf, len); if (t != len) { ERRS("Unable to write to %s", name); goto close; @@ -109,7 +117,7 @@ static int pad_image(char *name, uint32_t pad_mask) } /* write out the JFFS end-of-filesystem marker */ - t = write(fd, pad, pad_len); + t = write(outfd, pad, pad_len); if (t != pad_len) { ERRS("Unable to write to %s", name); goto close; @@ -137,6 +145,7 @@ static int usage(void) " This is used to work around broken boot loaders that\n" " try to parse the entire firmware area as one big jffs2\n" " -j: (like -J, but little-endian instead of big-endian)\n" + " -c: write padding to stdout\n" "\n", progname); return EXIT_FAILURE; @@ -160,7 +169,7 @@ int main(int argc, char* argv[]) argc--; pad_mask = 0; - while ((ch = getopt(argc, argv, "x:Jj")) != -1) { + while ((ch = getopt(argc, argv, "x:Jjc")) != -1) { switch (ch) { case 'x': xtra_offset = strtoul(optarg, NULL, 0); @@ -175,6 +184,9 @@ int main(int argc, char* argv[]) pad = jffs2_pad_le; pad_len = sizeof(jffs2_pad_le) - 1; break; + case 'c': + pad_to_stdout = true; + break; default: return usage(); } |