#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
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); \
{
char *buf;
int fd;
+ int outfd;
ssize_t in_len;
ssize_t out_len;
int ret = -1;
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;
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;
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;
}
/* 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;
" 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;
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);
pad = jffs2_pad_le;
pad_len = sizeof(jffs2_pad_le) - 1;
break;
+ case 'c':
+ pad_to_stdout = true;
+ break;
default:
return usage();
}