linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Stanley.Miao" <stanley.miao@windriver.com>
To: Artem.Bityutskiy@nokia.com
Cc: linux-mtd@lists.infradead.org
Subject: [PATCH 3/3] Place the cleanmarker in OOB area according to the mode MTD_OOB_AUTO
Date: Fri, 11 Jun 2010 17:36:15 +0800	[thread overview]
Message-ID: <1276248975-1822-4-git-send-email-stanley.miao@windriver.com> (raw)
In-Reply-To: <1276248975-1822-3-git-send-email-stanley.miao@windriver.com>

In the current linux kernel, Jffs2 writes the cleanmarker according to the
mode MTD_OOB_AUTO, so modify the layout of the cleanmarker from
MTD_OOB_PLACE to MTD_OOB_AUTO in flash_eraseall.

Signed-off-by: Stanley.Miao <stanley.miao@windriver.com>
---
 flash_eraseall.c |   40 ++++++++++++++++++++++------------------
 1 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/flash_eraseall.c b/flash_eraseall.c
index 4e2108b..f0f0371 100644
--- a/flash_eraseall.c
+++ b/flash_eraseall.c
@@ -34,7 +34,7 @@
 #include <time.h>
 #include <getopt.h>
 #include <sys/ioctl.h>
-#include <sys/mount.h>
+#include <sys/param.h>
 #include "crc32.h"
 
 #include <mtd/mtd-user.h>
@@ -75,9 +75,11 @@ static int get_linux_version(void)
 int main (int argc, char *argv[])
 {
 	mtd_info_t meminfo;
-	int fd, clmpos = 0, clmlen = 8;
+	int fd;
 	erase_info_t erase;
 	int isNAND, bbtest = 1;
+	unsigned char oobbuf[128];
+	memset(oobbuf, 0xFF, 128);
 
 	process_options(argc, argv);
 
@@ -98,11 +100,18 @@ 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 (struct jffs2_unknown_node));
-		else {
+			cleanmarker.hdr_crc = cpu_to_je32(crc32(0, &cleanmarker, \
+						sizeof(struct jffs2_unknown_node) - 4));
+		} else {
+			int already_read, num, i, start;
 			struct nand_ecclayout ecclayout;
 
+			cleanmarker.totlen = cpu_to_je32(8);
+			cleanmarker.hdr_crc = cpu_to_je32(crc32(0, &cleanmarker, \
+						sizeof(struct jffs2_unknown_node) - 4));
+
 			memset(&ecclayout, 0, sizeof(ecclayout));
 			if (get_linux_version() > LINUX_VERSION(2, 6, 17)) {
 				if (ioctl(fd, ECCGETLAYOUT, &ecclayout) != 0) {
@@ -122,19 +131,14 @@ int main (int argc, char *argv[])
 				memcpy(&ecclayout.oobfree, &oi.oobfree, sizeof(oi.oobfree));
 				ecclayout.eccbytes = oi.eccbytes;
 			}
-
-			/* Get the position of the free bytes */
-			if (!ecclayout.oobfree[0].length) {
-				fprintf(stderr, " Eeep. Autoplacement selected and no empty space in oob\n");
-				return 1;
+			already_read = 0;
+			for (i = 0; (already_read < 8) && ecclayout.oobfree[i].length; i++) {
+				num = MIN(8 - already_read, ecclayout.oobfree[i].length);
+				start = ecclayout.oobfree[i].offset;
+				memcpy(oobbuf + start, (unsigned char *)&cleanmarker + already_read, num);
+				already_read += num;
 			}
-			clmpos = ecclayout.oobfree[0].offset;
-			clmlen = ecclayout.oobfree[0].length;
-			if (clmlen > 8)
-				clmlen = 8;
-			cleanmarker.totlen = cpu_to_je32(8);
 		}
-		cleanmarker.hdr_crc =  cpu_to_je32 (crc32 (0, &cleanmarker,  sizeof (struct jffs2_unknown_node) - 4));
 	}
 
 	for (erase.start = 0; erase.start < meminfo.size; erase.start += meminfo.erasesize) {
@@ -174,9 +178,9 @@ int main (int argc, char *argv[])
 		/* write cleanmarker */
 		if (isNAND) {
 			struct mtd_oob_buf oob;
-			oob.ptr = (unsigned char *) &cleanmarker;
-			oob.start = erase.start + clmpos;
-			oob.length = clmlen;
+			oob.ptr = oobbuf;
+			oob.start = erase.start;
+			oob.length = meminfo.oobsize;
 			if (ioctl (fd, MEMWRITEOOB, &oob) != 0) {
 				fprintf(stderr, "\n%s: %s: MTD writeoob failure: %s\n", exe_name, mtd_device, strerror(errno));
 				continue;
-- 
1.5.4.3

  reply	other threads:[~2010-06-11  9:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-11  9:36 Fix mtd-utils bugs Stanley.Miao
2010-06-11  9:36 ` [PATCH 1/3] clean up the legacy interfaces in nandwrite.c Stanley.Miao
2010-06-11  9:36   ` [PATCH 2/3] Discard the legacy interface MEMGETOOBSEL in flash_eraseall Stanley.Miao
2010-06-11  9:36     ` Stanley.Miao [this message]
2010-06-11  9:44     ` Joakim Tjernlund
     [not found]     ` <OFDBEF7A42.BA0205E8-ONC125773F.0034F62C-C125773F.00358229@LocalDomain>
2010-06-11  9:53       ` Joakim Tjernlund
2010-06-11 10:36         ` stanley.miao
2010-06-11 10:44           ` Joakim Tjernlund
2010-06-11 12:11             ` Joakim Tjernlund
2010-06-13  9:51 ` Fix mtd-utils bugs Artem Bityutskiy
2010-06-13 10:14   ` Artem Bityutskiy
2010-06-17  4:10     ` stanley.miao
2010-06-18  8:16     ` stanley.miao
2010-06-18 10:24       ` Artem Bityutskiy
2010-06-20 12:21         ` stanley.miao
  -- strict thread matches above, loose matches on Subject: below --
2010-06-10  9:09 The "struct nand_oobinfo" is able to record only 32 ECC code positions, which Stanley.Miao
2010-06-10  9:09 ` [PATCH 1/3] clean up the legacy interfaces in nandwrite.c Stanley.Miao
2010-06-10  9:09   ` [PATCH 2/3] Discard the legacy interface MEMGETOOBSEL in flash_eraseall Stanley.Miao
2010-06-10  9:09     ` [PATCH 3/3] Place the cleanmarker in OOB area according to the mode MTD_OOB_AUTO Stanley.Miao

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=1276248975-1822-4-git-send-email-stanley.miao@windriver.com \
    --to=stanley.miao@windriver.com \
    --cc=Artem.Bityutskiy@nokia.com \
    --cc=linux-mtd@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).