mtd: fix trx_fixup
authorFelix Fietkau <nbd@openwrt.org>
Wed, 25 Jul 2012 17:28:32 +0000 (17:28 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Wed, 25 Jul 2012 17:28:32 +0000 (17:28 +0000)
With the BRCM47xx image I have built (Linksys E3000), there are additional
writes following the completion of "mtd_replace_jffs2" which invalidate the
'trx_fixup' performed by 'mtd_replace_jffs2'.  Moving the 'trx_fixup' to somewhere
after all writes have completed fixes the problem.  I also noticed that 'erasesize'
used to compute 'block_offset' in 'mtd_fixtrx' is used before it is computed by
'mtd_check_open'; moving the call to 'mtd_check_open' up a few lines fixes this.

Unlike 'mtd_fixtrx', 'trx_fixup' appears to assume that the TRX header is always at
offset 0; which may be the cause of the problem described in Ticket #8960.

Signed-off-by: Nathan Hintz <nlhintz@hotmail.com>
SVN-Revision: 32866

package/mtd/Makefile
package/mtd/src/jffs2.c
package/mtd/src/mtd.c
package/mtd/src/trx.c

index 27338d783b243ada562f69dff1eef102d476313c..7ca6b0e62564aab2a5b93a55019648f14889e216 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=mtd
 include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=mtd
-PKG_RELEASE:=17
+PKG_RELEASE:=18
 
 PKG_BUILD_DIR := $(KERNEL_BUILD_DIR)/$(PKG_NAME)
 STAMP_PREPARED := $(STAMP_PREPARED)_$(call confvar,CONFIG_MTD_REDBOOT_PARTS)
 
 PKG_BUILD_DIR := $(KERNEL_BUILD_DIR)/$(PKG_NAME)
 STAMP_PREPARED := $(STAMP_PREPARED)_$(call confvar,CONFIG_MTD_REDBOOT_PARTS)
index aaf9be5a928cc20ddaff92ea4aa7a837c770fae8..2a83bd47f4aa2ba5422cffae1d37991758468f5e 100644 (file)
@@ -244,9 +244,6 @@ int mtd_replace_jffs2(const char *mtd, int fd, int ofs, const char *filename)
        pad(erasesize);
        free(buf);
 
        pad(erasesize);
        free(buf);
 
-       if (trx_fixup) {
-         trx_fixup(outfd, mtd);
-       }
        return (mtdofs - ofs);
 }
 
        return (mtdofs - ofs);
 }
 
index 92873ca19b775eb84bb714d1cfc0e643b7ef78a4..18efcf57cf144d8e977995e38d1c415345b4b5c4 100644 (file)
@@ -294,6 +294,7 @@ mtd_write(int imagefd, const char *mtd, char *fis_layout, size_t part_offset)
        ssize_t r, w, e;
        ssize_t skip = 0;
        uint32_t offset = 0;
        ssize_t r, w, e;
        ssize_t skip = 0;
        uint32_t offset = 0;
+       int jffs2_replaced = 0;
 
 #ifdef FIS_SUPPORT
        static struct fis_part new_parts[MAX_ARGS];
 
 #ifdef FIS_SUPPORT
        static struct fis_part new_parts[MAX_ARGS];
@@ -417,6 +418,7 @@ resume:
                                        fprintf(stderr, "\nAppending jffs2 data from %s to %s...", jffs2file, mtd);
                                /* got an EOF marker - this is the place to add some jffs2 data */
                                skip = mtd_replace_jffs2(mtd, fd, e, jffs2file);
                                        fprintf(stderr, "\nAppending jffs2 data from %s to %s...", jffs2file, mtd);
                                /* got an EOF marker - this is the place to add some jffs2 data */
                                skip = mtd_replace_jffs2(mtd, fd, e, jffs2file);
+                               jffs2_replaced = 1;
 
                                /* don't add it again */
                                jffs2file = NULL;
 
                                /* don't add it again */
                                jffs2file = NULL;
@@ -482,6 +484,10 @@ resume:
                offset = 0;
        }
 
                offset = 0;
        }
 
+       if (jffs2_replaced && trx_fixup) {
+               trx_fixup(fd, mtd);
+       }
+
        if (!quiet)
                fprintf(stderr, "\b\b\b\b    ");
 
        if (!quiet)
                fprintf(stderr, "\b\b\b\b    ");
 
@@ -575,7 +581,7 @@ int main (int argc, char **argv)
        force = 0;
        buflen = 0;
        quiet = 0;
        force = 0;
        buflen = 0;
        quiet = 0;
-  no_erase = 0;
+       no_erase = 0;
 
        while ((ch = getopt(argc, argv,
 #ifdef FIS_SUPPORT
 
        while ((ch = getopt(argc, argv,
 #ifdef FIS_SUPPORT
index d1aab3692309726b6dede2ffc5d335149d2d282a..65c24404c2c1fe771acf0f78936b7bbe187a944c 100644 (file)
@@ -154,15 +154,15 @@ mtd_fixtrx(const char *mtd, size_t offset)
        if (quiet < 2)
                fprintf(stderr, "Trying to fix trx header in %s at 0x%x...\n", mtd, offset);
 
        if (quiet < 2)
                fprintf(stderr, "Trying to fix trx header in %s at 0x%x...\n", mtd, offset);
 
-       block_offset = offset & ~(erasesize - 1);
-       offset -= block_offset;
-
        fd = mtd_check_open(mtd);
        if(fd < 0) {
                fprintf(stderr, "Could not open mtd device: %s\n", mtd);
                exit(1);
        }
 
        fd = mtd_check_open(mtd);
        if(fd < 0) {
                fprintf(stderr, "Could not open mtd device: %s\n", mtd);
                exit(1);
        }
 
+       block_offset = offset & ~(erasesize - 1);
+       offset -= block_offset;
+
        if (block_offset + erasesize > mtdsize) {
                fprintf(stderr, "Offset too large, device size 0x%x\n", mtdsize);
                exit(1);
        if (block_offset + erasesize > mtdsize) {
                fprintf(stderr, "Offset too large, device size 0x%x\n", mtdsize);
                exit(1);