linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for mtd-utils] flash_erase: check the nand type
@ 2013-10-24  6:06 Huang Shijie
  2013-10-24  8:00 ` Brian Norris
  0 siblings, 1 reply; 2+ messages in thread
From: Huang Shijie @ 2013-10-24  6:06 UTC (permalink / raw)
  To: dwmw2; +Cc: Huang Shijie, computersforpeace, linux-mtd, dedekind1

Now, the MTD_NANDFLASH stands for SLC nand, and the MTD_MLCNANDFLASH
stands for the MLC nand.

This patch checks the right nand type for the MLC and SLC nand.
And if it is a MLC nand, we do not write cleanmarker for it, only print
out a message to warn the user.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 flash_erase.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/flash_erase.c b/flash_erase.c
index 1421cf9..dd75334 100644
--- a/flash_erase.c
+++ b/flash_erase.c
@@ -184,7 +184,8 @@ int main(int argc, char *argv[])
 
 	eb_start = start / mtd.eb_size;
 
-	isNAND = mtd.type == MTD_NANDFLASH ? 1 : 0;
+	isNAND = (mtd.type == MTD_NANDFLASH || mtd.type == MTD_MLCNANDFLASH)
+			? 1 : 0;
 
 	if (jffs2) {
 		cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
@@ -272,6 +273,12 @@ int main(int argc, char *argv[])
 
 		/* write cleanmarker */
 		if (isNAND) {
+			if (mtd.type == MTD_MLCNANDFLASH) {
+				sys_errmsg("%s: we can't write the cleanmarker "
+					"for the MLC nand.", mtd_device);
+				continue;
+			}
+
 			if (mtd_write_oob(mtd_desc, &mtd, fd, (uint64_t)offset + clmpos, clmlen, &cleanmarker) != 0) {
 				sys_errmsg("%s: MTD writeoob failure", mtd_device);
 				continue;
-- 
1.7.2.rc3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH for mtd-utils] flash_erase: check the nand type
  2013-10-24  6:06 [PATCH for mtd-utils] flash_erase: check the nand type Huang Shijie
@ 2013-10-24  8:00 ` Brian Norris
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Norris @ 2013-10-24  8:00 UTC (permalink / raw)
  To: Huang Shijie; +Cc: linux-mtd, dwmw2, dedekind1

On Thu, Oct 24, 2013 at 02:06:06PM +0800, Huang Shijie wrote:
> Now, the MTD_NANDFLASH stands for SLC nand, and the MTD_MLCNANDFLASH
> stands for the MLC nand.
> 
> This patch checks the right nand type for the MLC and SLC nand.
> And if it is a MLC nand, we do not write cleanmarker for it, only print
> out a message to warn the user.
> 
> Signed-off-by: Huang Shijie <b32955@freescale.com>
> ---
>  flash_erase.c |    9 ++++++++-
>  1 files changed, 8 insertions(+), 1 deletions(-)
> 
> diff --git a/flash_erase.c b/flash_erase.c
> index 1421cf9..dd75334 100644
> --- a/flash_erase.c
> +++ b/flash_erase.c
> @@ -184,7 +184,8 @@ int main(int argc, char *argv[])
>  
>  	eb_start = start / mtd.eb_size;
>  
> -	isNAND = mtd.type == MTD_NANDFLASH ? 1 : 0;
> +	isNAND = (mtd.type == MTD_NANDFLASH || mtd.type == MTD_MLCNANDFLASH)
> +			? 1 : 0;

Perhaps you can #include <stdbool.h> and make 'isNAND' into a proper
bool variable? Then this becomes:

	isNAND = mtd.type == MTD_NANDFLASH || mtd.type == MTD_MLCNANDFLASH;

>  
>  	if (jffs2) {
>  		cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
> @@ -272,6 +273,12 @@ int main(int argc, char *argv[])
>  
>  		/* write cleanmarker */
>  		if (isNAND) {
> +			if (mtd.type == MTD_MLCNANDFLASH) {
> +				sys_errmsg("%s: we can't write the cleanmarker "
> +					"for the MLC nand.", mtd_device);
> +				continue;
> +			}
> +

This is in a loop. This will print the same message repeatedly if you
are erasing/marking an entire partition. Please test your changes before
sending v2.

You could probably just error out (or warn) like the following.

diff --git a/flash_erase.c b/flash_erase.c
index 1421cf9..0e385e9 100644
--- a/flash_erase.c
+++ b/flash_erase.c
@@ -169,6 +169,9 @@ int main(int argc, char *argv[])
 	if (error)
 		return errmsg("Try `--help' for more information");
 
+	if (jffs2 && mtd.type == MTD_MLCNANDFLASH)
+		return errmsg("JFFS2 cannot support MLC NAND");
+
 	/*
 	 * Locate MTD and prepare for erasure
 	 */

>  			if (mtd_write_oob(mtd_desc, &mtd, fd, (uint64_t)offset + clmpos, clmlen, &cleanmarker) != 0) {
>  				sys_errmsg("%s: MTD writeoob failure", mtd_device);
>  				continue;

Brian

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-10-24  8:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-24  6:06 [PATCH for mtd-utils] flash_erase: check the nand type Huang Shijie
2013-10-24  8:00 ` Brian Norris

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).