From patchwork Wed Aug 3 05:50:38 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: 108023 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id BF75EB74E5 for ; Wed, 3 Aug 2011 16:50:01 +1000 (EST) Received: by ozlabs.org (Postfix) id AD37DB71E5; Wed, 3 Aug 2011 16:49:53 +1000 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: from ch1outboundpool.messaging.microsoft.com (ch1ehsobe006.messaging.microsoft.com [216.32.181.186]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client CN "mail.global.frontbridge.com", Issuer "Microsoft Secure Server Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id 3D364B71E4 for ; Wed, 3 Aug 2011 16:49:53 +1000 (EST) Received: from mail145-ch1-R.bigfish.com (216.32.181.172) by CH1EHSOBE015.bigfish.com (10.43.70.65) with Microsoft SMTP Server id 14.1.225.22; Wed, 3 Aug 2011 06:49:49 +0000 Received: from mail145-ch1 (localhost.localdomain [127.0.0.1]) by mail145-ch1-R.bigfish.com (Postfix) with ESMTP id 3158012F82DE; Wed, 3 Aug 2011 06:49:49 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h839h65h) X-Spam-TCS-SCL: 4: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 mail145-ch1 (localhost.localdomain [127.0.0.1]) by mail145-ch1 (MessageSwitch) id 1312354188977612_14756; Wed, 3 Aug 2011 06:49:48 +0000 (UTC) Received: from CH1EHSMHS035.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.242]) by mail145-ch1.bigfish.com (Postfix) with ESMTP id DACBABB8050; Wed, 3 Aug 2011 06:49:48 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS035.bigfish.com (10.43.70.35) with Microsoft SMTP Server (TLS) id 14.1.225.22; Wed, 3 Aug 2011 06:49:48 +0000 Received: from az33smr02.freescale.net (10.64.34.200) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server id 14.1.289.8; Wed, 3 Aug 2011 01:49:47 -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 p736njk5013999; Wed, 3 Aug 2011 01:49:46 -0500 (CDT) From: To: , Subject: [PATCH] mtd-utils: fix corrupt cleanmarker with flash_erase -j command Date: Wed, 3 Aug 2011 13:50:38 +0800 Message-ID: <1312350638-25566-1-git-send-email-b35362@freescale.com> X-Mailer: git-send-email 1.6.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com Cc: Liu Shuo , linuxppc-dev@ozlabs.org, linux-mtd@lists.infradead.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.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. Signed-off-by: Liu Shuo Signed-off-by: Li Yang --- flash_erase.c | 41 +++++++++++++++++++++++++++++++++++------ 1 files changed, 35 insertions(+), 6 deletions(-) diff --git a/flash_erase.c b/flash_erase.c index fe2eaca..e6747fc 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,40 @@ 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) { + struct nand_ecclayout_user ecclayout; /* Get the position of the free bytes */ - if (!oobinfo.oobfree[0][1]) + if (ioctl(fd, ECCGETLAYOUT, &ecclayout) != 0) + return sys_errmsg("%s: unable to get NAND ecclayout", mtd_device); + + if (!ecclayout.oobavail) return errmsg(" Eeep. Autoplacement selected and no empty space in oob"); clmpos = oobinfo.oobfree[0][0]; - clmlen = oobinfo.oobfree[0][1]; - if (clmlen > 8) - clmlen = 8; + clmlen = MIN(ecclayout.oobavail, 8); + + if (oobinfo.oobfree[0][1] < 8 && ecclayout.oobavail >= 8) { + int i, 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 +249,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 +297,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 +317,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; }