From patchwork Mon Aug 8 08:16:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: b35362@freescale.com X-Patchwork-Id: 108873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 30B0FB6F64 for ; Mon, 8 Aug 2011 19:16:49 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QqLws-0004kZ-Qi; Mon, 08 Aug 2011 09:16:39 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QqLws-0003Zj-BY; Mon, 08 Aug 2011 09:16:38 +0000 Received: from ch1ehsobe002.messaging.microsoft.com ([216.32.181.182] helo=ch1outboundpool.messaging.microsoft.com) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QqLwo-0003ZP-Ry for linux-mtd@lists.infradead.org; Mon, 08 Aug 2011 09:16:36 +0000 Received: from mail178-ch1-R.bigfish.com (216.32.181.173) by CH1EHSOBE015.bigfish.com (10.43.70.65) with Microsoft SMTP Server id 14.1.225.22; Mon, 8 Aug 2011 09:16:33 +0000 Received: from mail178-ch1 (localhost.localdomain [127.0.0.1]) by mail178-ch1-R.bigfish.com (Postfix) with ESMTP id 7B8571AD0311; Mon, 8 Aug 2011 09:16:33 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h839h63h) X-Spam-TCS-SCL: 2:0 X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPVD:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail178-ch1 (localhost.localdomain [127.0.0.1]) by mail178-ch1 (MessageSwitch) id 131279499385012_18632; Mon, 8 Aug 2011 09:16:33 +0000 (UTC) Received: from CH1EHSMHS031.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.254]) by mail178-ch1.bigfish.com (Postfix) with ESMTP id 10547AD804C; Mon, 8 Aug 2011 09:16:33 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS031.bigfish.com (10.43.70.31) with Microsoft SMTP Server (TLS) id 14.1.225.22; Mon, 8 Aug 2011 09:16:32 +0000 Received: from az33smr02.freescale.net (10.64.34.200) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server id 14.1.323.2; Mon, 8 Aug 2011 04:16:31 -0500 Received: from localhost (rock.ap.freescale.net [10.193.20.106]) by az33smr02.freescale.net (8.13.1/8.13.0) with ESMTP id p789GTTB008321; Mon, 8 Aug 2011 04:16:30 -0500 (CDT) From: To: Subject: [PATCH] mtd-utils: fix corrupt cleanmarker with flash_erase -j command Date: Mon, 8 Aug 2011 16:16:43 +0800 Message-ID: <1312791403-13473-1-git-send-email-b35362@freescale.com> X-Mailer: git-send-email 1.6.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110808_051635_040681_EE0ADDB9 X-CRM114-Status: GOOD ( 19.78 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [216.32.181.182 listed in list.dnswl.org] Cc: Liu Shuo , Artem.Bityutskiy@nokia.com, Li Yang , linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Liu Shuo Flash_erase -j should fill discrete freeoob areas with required bytes of JFFS2 cleanmarker in jffs2_check_nand_cleanmarker(). Not just fill the first freeoob area. The below is the result without this workaround: JFFS2: Erase block at 0x00000000 is not formatted. It will be erased JFFS2: Erase block at 0x00004000 is not formatted. It will be erased JFFS2: Erase block at 0x00008000 is not formatted. It will be erased JFFS2: Erase block at 0x0000c000 is not formatted. It will be erased JFFS2: Erase block at 0x00010000 is not formatted. It will be erased JFFS2: Erase block at 0x00014000 is not formatted. It will be erased JFFS2: Erase block at 0x00018000 is not formatted. It will be erased JFFS2: Erase block at 0x0001c000 is not formatted. It will be erased JFFS2: Erase block at 0x00020000 is not formatted. It will be erased JFFS2: Erase block at 0x00024000 is not formatted. It will be erased JFFS2: Erase block at 0x00028000 is not formatted. It will be erased ... Signed-off-by: Liu Shuo Signed-off-by: Li Yang --- v2 : get length of availble freeoob bytes from oobinfo information, not use the ioctl ECCGETLAYOUT which is being deprecated. flash_erase.c | 46 +++++++++++++++++++++++++++++++++++++++------- 1 files changed, 39 insertions(+), 7 deletions(-) diff --git a/flash_erase.c b/flash_erase.c index fe2eaca..3e94495 100644 --- a/flash_erase.c +++ b/flash_erase.c @@ -98,6 +98,7 @@ int main(int argc, char *argv[]) int isNAND; int error = 0; uint64_t offset = 0; + void *oob_data = NULL; /* * Process user arguments @@ -197,15 +198,43 @@ int main(int argc, char *argv[]) if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0) return sys_errmsg("%s: unable to get NAND oobinfo", mtd_device); + cleanmarker.totlen = cpu_to_je32(8); /* Check for autoplacement */ if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) { - /* Get the position of the free bytes */ - if (!oobinfo.oobfree[0][1]) + struct nand_ecclayout_user ecclayout; + int i, oobavail; + + for (i = 0, oobavail = 0; oobinfo.oobfree[i][1]; i++) + oobavail += oobinfo.oobfree[i][1]; + + if (!oobavail) return errmsg(" Eeep. Autoplacement selected and no empty space in oob"); + + /* Get the position of the free bytes */ clmpos = oobinfo.oobfree[0][0]; - clmlen = oobinfo.oobfree[0][1]; - if (clmlen > 8) - clmlen = 8; + clmlen = MIN(oobavail, 8); + + if (oobinfo.oobfree[0][1] < 8 && oobavail >= 8) { + int left, n, last = 0; + void *cm; + + oob_data = malloc(mtd.oob_size); + if (!oob_data) + return -ENOMEM; + + memset(oob_data, 0xff, mtd.oob_size); + cm = &cleanmarker; + for (i = 0, left = clmlen; left ; i++) { + n = MIN(left, oobinfo.oobfree[i][1]); + memcpy(oob_data + oobinfo.oobfree[i][0], + cm, n); + left -= n; + cm += n; + last = oobinfo.oobfree[i][0] + n; + } + + clmlen = last - clmpos; + } } else { /* Legacy mode */ switch (mtd.oob_size) { @@ -223,7 +252,6 @@ int main(int argc, char *argv[]) break; } } - cleanmarker.totlen = cpu_to_je32(8); } cleanmarker.hdr_crc = cpu_to_je32(mtd_crc32(0, &cleanmarker, sizeof(cleanmarker) - 4)); } @@ -272,7 +300,8 @@ int main(int argc, char *argv[]) /* write cleanmarker */ if (isNAND) { - if (mtd_write_oob(mtd_desc, &mtd, fd, offset + clmpos, clmlen, &cleanmarker) != 0) { + void *data = oob_data ? oob_data + clmpos : &cleanmarker; + if (mtd_write_oob(mtd_desc, &mtd, fd, offset + clmpos, clmlen, data) != 0) { sys_errmsg("%s: MTD writeoob failure", mtd_device); continue; } @@ -291,5 +320,8 @@ int main(int argc, char *argv[]) show_progress(&mtd, offset, eb, eb_start, eb_cnt); bareverbose(!quiet, "\n"); + if (oob_data) + free(oob_data); + return 0; }