From patchwork Tue Apr 12 09:58:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daid X-Patchwork-Id: 90763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C2134B6F1B for ; Tue, 12 Apr 2011 19:59:51 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by bombadil.infradead.org with esmtps (Exim 4.72 #1 (Red Hat Linux)) id 1Q9aMO-0002lz-Fb; Tue, 12 Apr 2011 09:58:12 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1Q9aMM-0006QU-UL; Tue, 12 Apr 2011 09:58:10 +0000 Received: from mail-vw0-f49.google.com ([209.85.212.49]) by canuck.infradead.org with esmtps (Exim 4.72 #1 (Red Hat Linux)) id 1Q9aMK-0006QB-5t for linux-mtd@lists.infradead.org; Tue, 12 Apr 2011 09:58:09 +0000 Received: by vws8 with SMTP id 8so6033653vws.36 for ; Tue, 12 Apr 2011 02:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=R1qxWwKBR2cUlwVoR+OweFcViNUiD1Fyo7zds3eIxcg=; b=FQ4pXKXis7c0NKBKpLFvtmT5fAsNE94L2D3DE7LWgGOrslqmJMyi9txAZLmpG1cLGk L7Q6+lb5Prr5W0FlOzVs6IzlGF2qWxmYpDEmRrtD+Kren/Yd4jymmAUSoiHBVygob1fB FIZvIUkpFT7Gn/5mRbiZsLjSdeeCI4oldW2To= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=BSrw8B42+mSnCx3zdgEJtce4q4oDxCh5d2un14zs82vLiOAZuAEjbadtpI8LgRczhc DEoNvFmNUdQ+ypz/38dlfwIpeWYkkgwDOLmVgzJNSbWrbl/RdS6O1fFkca5rZS+Ty4b1 UvwMn6PHMzo7nsc87fYeZsizK85RmWGUZgA04= MIME-Version: 1.0 Received: by 10.220.129.14 with SMTP id m14mr1870882vcs.109.1302602286591; Tue, 12 Apr 2011 02:58:06 -0700 (PDT) Received: by 10.220.63.79 with HTTP; Tue, 12 Apr 2011 02:58:06 -0700 (PDT) Date: Tue, 12 Apr 2011 11:58:06 +0200 Message-ID: Subject: mtd-utils: "flash_erase -j" failes with "unable to get NAND oobinfo" on large flash chips. From: Daid To: linux-mtd@lists.infradead.org X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110412_055808_381473_9716C0F0 X-CRM114-Status: GOOD ( 13.01 ) X-Spam-Score: 1.4 (+) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (1.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is freemail (daid303[at]gmail.com) 2.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (daid303[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.49 listed in list.dnswl.org] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL 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 I've made a patch to fix flash_erase with large flash chips. flash_erase uses MEMGETOOBSEL which no longer works if the ECC area is larger then 32 bytes. ECCGETLAYOUT is the replacement ioctl. This patch is based on the work of Stanley Miao, he made a patch in June 2010 for flash_eraseall. http://lists.infradead.org/pipermail/linux-mtd/2010-June/031981.html I've implemented the backwards compatibility differently, checking kernel versions doesn't feel correct. } cleanmarker.hdr_crc = cpu_to_je32(mtd_crc32(0, &cleanmarker, sizeof(cleanmarker) - 4)); diff -ur mtd-utils-v1.4.4/flash_erase.c mtd-utils-patch/flash_erase.c --- mtd-utils-v1.4.4/flash_erase.c 2011-04-01 18:31:43.000000000 +0200 +++ mtd-utils-patch/flash_erase.c 2011-04-12 11:41:43.000000000 +0200 @@ -193,37 +193,57 @@ if (!isNAND) cleanmarker.totlen = cpu_to_je32(sizeof(cleanmarker)); else { - struct nand_oobinfo oobinfo; +#if defined(ECCGETLAYOUT) + struct nand_ecclayout ecclayout; - if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0) - return sys_errmsg("%s: unable to get NAND oobinfo", mtd_device); - - /* Check for autoplacement */ - if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) { + memset(&ecclayout, 0, sizeof(ecclayout)); + if (ioctl(fd, ECCGETLAYOUT, &ecclayout) == 0) { /* Get the position of the free bytes */ - if (!oobinfo.oobfree[0][1]) - 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; + if (!ecclayout.oobfree[0].length) { + fprintf(stderr, " Eeep. Autoplacement selected and no empty space in oob\n"); + return 1; + } + clmpos = ecclayout.oobfree[0].offset; + clmlen = ecclayout.oobfree[0].length; } else { - /* Legacy mode */ - switch (mtd.oob_size) { - case 8: - clmpos = 6; - clmlen = 2; - break; - case 16: - clmpos = 8; - clmlen = 8; - break; - case 64: - clmpos = 16; +#endif/*defined(ECCGETLAYOUT)*/ + /* new ECC interface failed or not available, fall back to old OOB interface, which does not support large flash */ + struct nand_oobinfo oobinfo; + if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0) + return sys_errmsg("%s: unable to get NAND oobinfo", mtd_device); + + /* Check for autoplacement */ + if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) { + /* Get the position of the free bytes */ + if (!oobinfo.oobfree[0][1]) + 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; - break; + } else { + /* Legacy mode */ + switch (mtd.oob_size) { + case 8: + clmpos = 6; + clmlen = 2; + break; + case 16: + clmpos = 8; + clmlen = 8; + break; + case 64: + clmpos = 16; + clmlen = 8; + break; + } } +#if defined(ECCGETLAYOUT) } +#endif/*defined(ECCGETLAYOUT)*/ + + if (clmlen > 8) + clmlen = 8; cleanmarker.totlen = cpu_to_je32(8);