padjffs2: add a different kind of padding (using standard jffs2 elements) to work around broken boot loaders for kernel partitions
Signed-off-by: Felix Fietkau <nbd@openwrt.org> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@38804 3c298f89-4303-0410-b956-a3cf2f4a3e73master
parent
3e44099b61
commit
559e45026b
|
@ -21,6 +21,10 @@
|
||||||
static char *progname;
|
static char *progname;
|
||||||
static unsigned int xtra_offset;
|
static unsigned int xtra_offset;
|
||||||
static unsigned char eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};
|
static unsigned char eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};
|
||||||
|
static unsigned char jffs2_pad_be[] = "\x19\x85\x20\x04\x04\x00\x00\x00\xc4\x94\xdb\xf4";
|
||||||
|
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);
|
||||||
|
|
||||||
#define ERR(fmt, ...) do { \
|
#define ERR(fmt, ...) do { \
|
||||||
fflush(0); \
|
fflush(0); \
|
||||||
|
@ -105,12 +109,12 @@ static int pad_image(char *name, uint32_t pad_mask)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write out the JFFS end-of-filesystem marker */
|
/* write out the JFFS end-of-filesystem marker */
|
||||||
t = write(fd, eof_mark, 4);
|
t = write(fd, pad, pad_len);
|
||||||
if (t != 4) {
|
if (t != pad_len) {
|
||||||
ERRS("Unable to write to %s", name);
|
ERRS("Unable to write to %s", name);
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
out_len += 4;
|
out_len += pad_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -123,39 +127,67 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int usage(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr,
|
||||||
|
"Usage: %s file [<options>] [pad0] [pad1] [padN]\n"
|
||||||
|
"Options:\n"
|
||||||
|
" -x <offset>: Add an extra offset for padding data\n"
|
||||||
|
" -J: Use a fake big-endian jffs2 padding element instead of EOF\n"
|
||||||
|
" 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"
|
||||||
|
"\n",
|
||||||
|
progname);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
char *image;
|
||||||
uint32_t pad_mask;
|
uint32_t pad_mask;
|
||||||
int ret = EXIT_FAILURE;
|
int ret = EXIT_FAILURE;
|
||||||
int err;
|
int err;
|
||||||
int i;
|
int ch, i;
|
||||||
|
|
||||||
progname = basename(argv[0]);
|
progname = basename(argv[0]);
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2)
|
||||||
fprintf(stderr,
|
return usage();
|
||||||
"Usage: %s file [-x <xtra offset>] [pad0] [pad1] [padN]\n",
|
|
||||||
progname);
|
image = argv[1];
|
||||||
goto out;
|
argv++;
|
||||||
}
|
argc--;
|
||||||
|
|
||||||
pad_mask = 0;
|
pad_mask = 0;
|
||||||
for (i = 2; i < argc; i++) {
|
while ((ch = getopt(argc, argv, "x:Jj")) != -1) {
|
||||||
if (i == 2 && strcmp(argv[i], "-x") == 0) {
|
switch (ch) {
|
||||||
i++;
|
case 'x':
|
||||||
xtra_offset = strtoul(argv[i], NULL, 0);
|
xtra_offset = strtoul(optarg, NULL, 0);
|
||||||
fprintf(stderr, "assuming %u bytes offset\n",
|
fprintf(stderr, "assuming %u bytes offset\n",
|
||||||
xtra_offset);
|
xtra_offset);
|
||||||
continue;
|
break;
|
||||||
|
case 'J':
|
||||||
|
pad = jffs2_pad_be;
|
||||||
|
pad_len = sizeof(jffs2_pad_be) - 1;
|
||||||
|
break;
|
||||||
|
case 'j':
|
||||||
|
pad = jffs2_pad_le;
|
||||||
|
pad_len = sizeof(jffs2_pad_le) - 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return usage();
|
||||||
}
|
}
|
||||||
pad_mask |= strtoul(argv[i], NULL, 0) * 1024;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = optind; i < argc; i++)
|
||||||
|
pad_mask |= strtoul(argv[i], NULL, 0) * 1024;
|
||||||
|
|
||||||
if (pad_mask == 0)
|
if (pad_mask == 0)
|
||||||
pad_mask = (4 * 1024) | (8 * 1024) | (64 * 1024) |
|
pad_mask = (4 * 1024) | (8 * 1024) | (64 * 1024) |
|
||||||
(128 * 1024);
|
(128 * 1024);
|
||||||
|
|
||||||
err = pad_image(argv[1], pad_mask);
|
err = pad_image(image, pad_mask);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue