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" is added to mtd, that allows to specify 
which jffs2 partition should be used when
the data is appended.

Signed-off-by: Peter Wagner <tripo...@gmx.at>
diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh
index 9116206..e01ffc5 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..d63eec2 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 jffs2count=1;
 
 int mtd_open(const char *mtd, bool block)
 {
@@ -381,6 +382,10 @@ resume:
 
 		if (jffs2file) {
 			if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF) - 1) == 0) {
+				if ( jffs2count > 1 ) {
+					--jffs2count;
+					goto skip_jffs2;
+				}
 				if (!quiet)
 					fprintf(stderr, "\b\b\b   ");
 				if (quiet < 2)
@@ -403,6 +408,7 @@ resume:
 			 * before appending some data */
 			mtd_parse_jffs2data(buf, jffs2dir);
 		}
+skip_jffs2:
 
 		/* need to erase the next block before writing data to it */
 		if(!no_erase)
@@ -503,6 +509,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>             append data to this jffs2 partiton (defaults to \"1\"\n"
 	"        -p                      write beginning at partition offset\n");
 	if (mtd_fixtrx) {
 	    fprintf(stderr,
@@ -560,7 +567,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 +581,14 @@ int main (int argc, char **argv)
 			case 'j':
 				jffs2file = optarg;
 				break;
+			case 's':
+				errno = 0;
+				jffs2count = 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..971e0a0 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 2"
+		default_do_upgrade "$ARGV"
+		;;
 	*)
 		default_do_upgrade "$ARGV"
 		;;
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to