On nand flash, identifies a jffs2 partition by looking for the jffs2 cleanmarker in the oob area instead of at the beginning of an erase block.
Signed-off-by: Ben Mulvihill <[email protected]> --- drivers/mtd/mtdsplit.c | 49 +++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) --- a/drivers/mtd/mtdsplit.c 2014-03-23 13:11:47.121375219 +0100 +++ b/drivers/mtd/mtdsplit.c 2014-03-23 13:12:59.555061660 +0100 @@ -70,6 +70,40 @@ static ssize_t mtd_next_eb(struct mtd_in return mtd_rounddown_to_eb(offset, mtd) + mtd->erasesize; } +static int cleanmarker_present_in_oob(struct mtd_info *mtd, size_t offset) +{ + struct mtd_oob_ops ops; + int ret; + u32 magic = 0; + int i; + + offset &= ~((uint64_t)mtd->writesize - 1); + + if (mtd->oobavail < sizeof (magic)) { + pr_alert("Cannot read OOB for EB at %08x\n", offset); + return 0; + } + + ops.oobbuf = (void *)&magic; + ops.ooblen = sizeof (magic); + ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0; + ops.datbuf = NULL; + + ops.mode = MTD_OPS_AUTO_OOB; + + + ret = mtd_read_oob(mtd, offset, &ops); + if ((ret && !mtd_is_bitflip(ret)) || ops.oobretlen != ops.ooblen) { + pr_alert("Cannot read OOB for EB at %08x, requested %zd bytes, read %zd bytes, error %d\n", + offset, ops.ooblen, ops.oobretlen, ret); + return 0; + } + + return (magic == 0x19852003 ? 1 : 0); +} + + + int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset) { u32 magic; @@ -84,11 +118,18 @@ int mtd_check_rootfs_magic(struct mtd_in if (retlen != sizeof(magic)) return -EIO; - if (le32_to_cpu(magic) != SQUASHFS_MAGIC && - magic != 0x19852003) - return -EINVAL; + if (le32_to_cpu(magic) == SQUASHFS_MAGIC) + return 0; + if (magic == 0x19852003) + return 0; + if (mtd->type == MTD_NANDFLASH) { + if (cleanmarker_present_in_oob (mtd, offset)) + return 0; + } + + return -EINVAL; + - return 0; } EXPORT_SYMBOL_GPL(mtd_check_rootfs_magic); _______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
