From patchwork Mon Apr 9 03:10:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiaolei li X-Patchwork-Id: 10330099 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 C93276022E for ; Mon, 9 Apr 2018 03:11:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9B482898E for ; Mon, 9 Apr 2018 03:11:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADC6F28996; Mon, 9 Apr 2018 03:11:28 +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 1B7362898E for ; Mon, 9 Apr 2018 03:11:26 +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=VrKyGVOoQa2gdZ LK7QQGVu/a/vy55NXvZf5lHm9wCz57c2UQrwisAJS9UEJ9N0A72fYOvPav9pdsYteT7Fgd6RbGog4 3dQQVCFsctqabwkuAJrR5hWkVFy5YiFtYrx4UjQN1M0S9ua7aFY/QLxfPFWCQLsP6TedQe1sJH8T9 wWtHUJbNacu3a6HxCNY50uMUrwKRgLuFEPx1EecKquZ9X1mtd0w8QXMJRSvCcx5LMsrWYRId0iyFQ HiiI3ZgjAz6Y+5xEsSEfl2aG28L1/QrvvFJLYw/F6e0jPkG5xvTNSe3qyEL4ChHeuV9HF38jDajEH VukCCnK56bimKyv7cX4w==; 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 1f5NDF-0006E1-6e; Mon, 09 Apr 2018 03:11:21 +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 1f5NDB-0005kM-JG; Mon, 09 Apr 2018 03:11:19 +0000 X-UUID: 0370aefec40541c9bf412663c1456106-20180409 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 2112137757; Mon, 09 Apr 2018 11:10:18 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Mon, 9 Apr 2018 11:10:18 +0800 Received: from mtkslt306.mediatek.inc (10.21.14.136) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Mon, 9 Apr 2018 11:10:17 +0800 From: Xiaolei Li To: , Subject: [PATCH 2/2] misc-utils: flash_erase: Fix Jffs2 type flash erase problem Date: Mon, 9 Apr 2018 11:10:10 +0800 Message-ID: <1523243410-65424-3-git-send-email-xiaolei.li@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523243410-65424-1-git-send-email-xiaolei.li@mediatek.com> References: <1523243410-65424-1-git-send-email-xiaolei.li@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-12.5.0.5042-8.2.9001-23772.004 X-TM-AS-Result: No-5.753600-8.000000-10 X-TMASE-MatchedRID: Eju1/7oqfG2OUvUSGKdRPkKcYi5Qw/RVUXlp1FHYSPXUM0gUto0wuCMO uGtF4L1EPzin/03CLtMgNFIGSbJIXaN0uxYINvQ1VnhTcytb5dIoteqd/zXaI01KG1YrOQW/cpw vkaGF/zvi8zVgXoAltsIJ+4gwXrEtwrbXMGDYqV8gWATM4opXZsE5Uc0+JoPHigifwmVenlJ+Oe W4vHmUw0DxkGJfWl9LVlxr1FJij9s= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--5.753600-8.000000 X-TMASE-Version: SMEX-12.5.0.5042-8.2.9001-23772.004 X-TMASE-POSTMAN: 2-d; X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180408_201117_767198_9E3B1C6D X-CRM114-Status: UNSURE ( 9.28 ) X-CRM114-Notice: Please train this message. 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;