public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
From: Xiaolei Li <xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
To: david.oberhollenzer-S6VGOU4v5edDinCvNWH78Q@public.gmane.org,
	boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org
Cc: linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org,
	linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	srv_heupstream-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org
Subject: [PATCH 2/2] misc-utils: flash_erase: Fix Jffs2 type flash erase problem
Date: Mon, 9 Apr 2018 11:10:10 +0800	[thread overview]
Message-ID: <1523243410-65424-3-git-send-email-xiaolei.li@mediatek.com> (raw)
In-Reply-To: <1523243410-65424-1-git-send-email-xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>

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 <xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
---
 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;
-- 
1.9.1

      parent reply	other threads:[~2018-04-09  3:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09  3:10 [PATCH 0/2] Fix Jffs2 type flash erase problem Xiaolei Li
     [not found] ` <1523243410-65424-1-git-send-email-xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2018-04-09  3:10   ` [PATCH 1/2] libmtd: Add support to access OOB available size Xiaolei Li
     [not found]     ` <1523243410-65424-2-git-send-email-xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2018-04-09  6:58       ` David Oberhollenzer
     [not found]         ` <99d17022-0b07-a999-b6ac-05b51df7d18d-S6VGOU4v5edDinCvNWH78Q@public.gmane.org>
2018-04-09  7:25           ` xiaolei li
2018-04-09  7:35             ` Boris Brezillon
2018-04-09  8:33               ` xiaolei li
2018-04-09  8:37                 ` Boris Brezillon
2018-04-09  8:45                   ` xiaolei li
2018-04-09  8:53                     ` David Oberhollenzer
     [not found]                       ` <bec14308-33e1-d158-37d2-4f59047f0016-S6VGOU4v5edDinCvNWH78Q@public.gmane.org>
2018-04-09  9:01                         ` xiaolei li
2018-04-09  3:10   ` Xiaolei Li [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1523243410-65424-3-git-send-email-xiaolei.li@mediatek.com \
    --to=xiaolei.li-nus5lvnupcjwk0htik3j/w@public.gmane.org \
    --cc=boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org \
    --cc=david.oberhollenzer-S6VGOU4v5edDinCvNWH78Q@public.gmane.org \
    --cc=linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=srv_heupstream-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox