Changelog:
V1: skip the first n-1 occurrence of JFFS2_EOF
V2: change argument handling
V3: skip first n bytes when appending jffs2 data
V4: remove quotes for $MTD_CONFIG_ARGS
V5: add nbd's jffs2 padding element code to work around broken boot loaders
jffs2 partition parsing now really happens after the specified number of
bytes
The current implementation of mtd will not append the backup
file created by sysupgrade to the correct partition, as mtd will append
the data to first jffs2 partition it finds. As the kernel is also
stored on a jffs2 partition (which resides before the overlay
partition), the data will be appended to this partition.
To fix this problem, a new option
-s <number> skip the first n bytes when appending data to the jffs2
partiton, defaults to "0"
is added to mtd.
nbd's code adds this options to padjffs2:
x <offset>: Add an extra offset for padding data
-J: Use a bogus jffs2 padding element instead of EOF
This is used to work around broken boot loaders that
try to parse the entire firmware area as one big jffs2
-j: (like -J, but little-endian instead of big-endian)
Signed-off-by: Peter Wagner <[email protected]>diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh
index 9116206..c19640f 100644
--- a/package/base-files/files/lib/upgrade/common.sh
+++ b/package/base-files/files/lib/upgrade/common.sh
@@ -188,7 +188,7 @@ jffs2_copy_config() {
default_do_upgrade() {
sync
if [ "$SAVE_CONFIG" -eq 1 ]; then
- get_image "$1" | mtd -j "$CONF_TAR" write - "${PART_NAME:-image}"
+ get_image "$1" | mtd $MTD_CONFIG_ARGS -j "$CONF_TAR" write - "${PART_NAME:-image}"
else
get_image "$1" | mtd write - "${PART_NAME:-image}"
fi
diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index eb5ab03..14b09eb 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -4,6 +4,7 @@
# initialize defaults
RAMFS_COPY_BIN="" # extra programs for temporary ramfs root
RAMFS_COPY_DATA="" # extra data files
+export MTD_CONFIG_ARGS=""
export INTERACTIVE=0
export VERBOSE=1
export SAVE_CONFIG=1
diff --git a/package/system/mtd/src/mtd.c b/package/system/mtd/src/mtd.c
index a660486..2ec02a8 100644
--- a/package/system/mtd/src/mtd.c
+++ b/package/system/mtd/src/mtd.c
@@ -55,6 +55,7 @@ int quiet;
int no_erase;
int mtdsize = 0;
int erasesize = 0;
+int jffs2_skip_bytes=0;
int mtd_open(const char *mtd, bool block)
{
@@ -339,7 +340,6 @@ resume:
fprintf(stderr, "Could not open mtd device: %s\n", mtd);
exit(1);
}
-
if (part_offset > 0) {
fprintf(stderr, "Seeking on mtd device '%s' to: %u\n", mtd, part_offset);
lseek(fd, part_offset, SEEK_SET);
@@ -379,7 +379,7 @@ resume:
continue;
}
- if (jffs2file) {
+ if (jffs2file && w >= jffs2_skip_bytes) {
if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF) - 1) == 0) {
if (!quiet)
fprintf(stderr, "\b\b\b ");
@@ -503,6 +503,7 @@ static void usage(void)
" -e <device> erase <device> before executing the command\n"
" -d <name> directory for jffs2write, defaults to \"tmp\"\n"
" -j <name> integrate <file> into jffs2 data when writing an image\n"
+ " -s <number> skip the first n bytes when appending data to the jffs2 partiton, defaults to \"0\"\n"
" -p write beginning at partition offset\n");
if (mtd_fixtrx) {
fprintf(stderr,
@@ -560,7 +561,7 @@ int main (int argc, char **argv)
#ifdef FIS_SUPPORT
"F:"
#endif
- "frnqe:d:j:p:o:")) != -1)
+ "frnqe:d:s:j:p:o:")) != -1)
switch (ch) {
case 'f':
force = 1;
@@ -574,6 +575,14 @@ int main (int argc, char **argv)
case 'j':
jffs2file = optarg;
break;
+ case 's':
+ errno = 0;
+ jffs2_skip_bytes = strtoul(optarg, 0, 0);
+ if (errno) {
+ fprintf(stderr, "-s: illegal numeric string\n");
+ usage();
+ }
+ break;
case 'q':
quiet++;
break;
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index 266bf3f..1eb9354 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -327,6 +327,10 @@ platform_do_upgrade() {
om2p-lc)
platform_do_upgrade_openmesh "$ARGV"
;;
+ uap-pro)
+ MTD_CONFIG_ARGS="-s 0x180000"
+ default_do_upgrade "$ARGV"
+ ;;
*)
default_do_upgrade "$ARGV"
;;
diff --git a/target/linux/ar71xx/image/Makefile b/target/linux/ar71xx/image/Makefile
index 3af8375..d1e91c0 100644
--- a/target/linux/ar71xx/image/Makefile
+++ b/target/linux/ar71xx/image/Makefile
@@ -448,7 +448,7 @@ define Image/Build/UAPPRO/buildkernel
-d $(KDIR_TMP)/$(2)/image \
2>&1 1>/dev/null | awk '/^.+$$$$/'
-rm -rf $(KDIR_TMP)/$(2)
- $(STAGING_DIR_HOST)/bin/padjffs2 $(KDIR_TMP)/$(2)-kernel.jffs2 64
+ $(STAGING_DIR_HOST)/bin/padjffs2 $(KDIR_TMP)/$(2)-kernel.jffs2 -J 64
endef
define Image/Build/UAPPRO
diff --git a/tools/padjffs2/src/padjffs2.c b/tools/padjffs2/src/padjffs2.c
index aa932ef..20a6dc9 100644
--- a/tools/padjffs2/src/padjffs2.c
+++ b/tools/padjffs2/src/padjffs2.c
@@ -21,6 +21,9 @@
static char *progname;
static unsigned int xtra_offset;
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 *pad = eof_mark;
+static int pad_len = sizeof(eof_mark);
#define ERR(fmt, ...) do { \
fflush(0); \
@@ -105,12 +108,12 @@ static int pad_image(char *name, uint32_t pad_mask)
}
/* write out the JFFS end-of-filesystem marker */
- t = write(fd, eof_mark, 4);
- if (t != 4) {
+ t = write(fd, pad, pad_len);
+ if (t != pad_len) {
ERRS("Unable to write to %s", name);
goto close;
}
- out_len += 4;
+ out_len += pad_len;
}
ret = 0;
@@ -123,39 +126,63 @@ out:
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 bogus 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[])
{
+ char *image;
uint32_t pad_mask;
int ret = EXIT_FAILURE;
int err;
- int i;
+ int ch, i;
progname = basename(argv[0]);
- if (argc < 2) {
- fprintf(stderr,
- "Usage: %s file [-x <xtra offset>] [pad0] [pad1] [padN]\n",
- progname);
- goto out;
- }
+ if (argc < 2)
+ return usage();
+
+ image = argv[1];
+ argv++;
+ argc--;
pad_mask = 0;
- for (i = 2; i < argc; i++) {
- if (i == 2 && strcmp(argv[i], "-x") == 0) {
- i++;
- xtra_offset = strtoul(argv[i], NULL, 0);
+ while ((ch = getopt(argc, argv, "x:Jj")) != -1) {
+ switch (ch) {
+ case 'x':
+ xtra_offset = strtoul(optarg, NULL, 0);
fprintf(stderr, "assuming %u bytes offset\n",
xtra_offset);
- continue;
+ break;
+ case 'J':
+ pad = jffs2_pad_be;
+ pad_len = sizeof(jffs2_pad_be) - 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)
pad_mask = (4 * 1024) | (8 * 1024) | (64 * 1024) |
(128 * 1024);
- err = pad_image(argv[1], pad_mask);
+ err = pad_image(image, pad_mask);
if (err)
goto out;
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel