From patchwork Tue Apr 10 07:36:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiaolei li X-Patchwork-Id: 10332447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 11F996053C for ; Tue, 10 Apr 2018 07:38:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00DC728C75 for ; Tue, 10 Apr 2018 07:38:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E961728C7A; Tue, 10 Apr 2018 07:38:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 79A4028C75 for ; Tue, 10 Apr 2018 07:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LjrWTUS0/ZGf3Aon6eXpPwo5YiB0ymNx/wZc0LRqdrE=; b=oMZz85IvtfTAG4 sJx8YZ0zLH91tqInovCg6hs7+jxi7RwQBP0Ktc9IvkfF54FXBuoUPDdOmCjSgaaekU0yBMHCGcNrp BZkIpSIMrCDwm+vW++DAtZhpiqa70abZsHtDtajuSHt29Y48J/1lkF40PMh+y6mBcTChEGfc2qvY4 sbck8wH9191PSCLpijw4kkRfkWgyp28WS9u68L+ZpfiJsTPy7CemEJbrVFK3C6KSeAfbNZsuZAPAP 2kMg2glwpsyxW3A3Ds8IOHO8tdM7EIZIibpNOBEh4iRCbQeKad1FK8R2EvoXqL6rDQIBybHlke6fC CZ6n1XjXpJSSYp6n9iOA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5nrP-0006hY-2P; Tue, 10 Apr 2018 07:38:35 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5nqH-00060x-7h; Tue, 10 Apr 2018 07:37:27 +0000 X-UUID: 2b63071d3d8e437788390c70ad45d4da-20180410 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 2111470429; Tue, 10 Apr 2018 15:37:04 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 10 Apr 2018 15:37:02 +0800 Received: from mtkslt306.mediatek.inc (10.21.14.136) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Tue, 10 Apr 2018 15:37:02 +0800 From: Xiaolei Li To: , Subject: [PATCH v2 3/3] misc-utils: flash_erase: Fix Jffs2 type flash erase problem Date: Tue, 10 Apr 2018 15:36:57 +0800 Message-ID: <1523345817-42627-4-git-send-email-xiaolei.li@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523345817-42627-1-git-send-email-xiaolei.li@mediatek.com> References: <1523345817-42627-1-git-send-email-xiaolei.li@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180410_003725_424935_558922BA X-CRM114-Status: GOOD ( 10.79 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mediatek@lists.infradead.org, xiaolei.li@mediatek.com, linux-mtd@lists.infradead.org, srv_heupstream@mediatek.com Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, Jffs2 clean marker is not written actually, because the oob write length is set to 0 when do mtd_write(). So, get OOB available size at first, and set the correct clean marker length, then program clean marker to free OOB area. Fixes: d7e86124d55b ("mtd-utils: Support jffs2 flash-erase for large OOB (>32b)") Signed-off-by: Xiaolei Li --- misc-utils/flash_erase.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/misc-utils/flash_erase.c b/misc-utils/flash_erase.c index 0c9449f..e7a00ae 100644 --- a/misc-utils/flash_erase.c +++ b/misc-utils/flash_erase.c @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) { libmtd_t mtd_desc; struct mtd_dev_info mtd; - int fd; + int fd, cmlen = 8; unsigned long long start; unsigned int eb, eb_start, eb_cnt; bool isNAND; @@ -190,10 +190,11 @@ int main(int argc, char *argv[]) if (jffs2) { cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK); cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER); - if (!isNAND) + if (!isNAND) { cleanmarker.totlen = cpu_to_je32(sizeof(cleanmarker)); - else { + } else { cleanmarker.totlen = cpu_to_je32(8); + cmlen = min(mtd.oobavail, 8); } cleanmarker.hdr_crc = cpu_to_je32(mtd_crc32(0, &cleanmarker, sizeof(cleanmarker) - 4)); } @@ -242,7 +243,7 @@ int main(int argc, char *argv[]) /* write cleanmarker */ if (isNAND) { - if (mtd_write(mtd_desc, &mtd, fd, eb, 0, NULL, 0, &cleanmarker, 0, + if (mtd_write(mtd_desc, &mtd, fd, eb, 0, NULL, 0, &cleanmarker, cmlen, MTD_OPS_AUTO_OOB) != 0) { sys_errmsg("%s: MTD writeoob failure", mtd_device); continue;