All of lore.kernel.org
 help / color / mirror / Atom feed
* Fix the bug that nandwrite can't write the yaffs2 image correctly
@ 2010-05-18 12:23 Stanley.Miao
  2010-05-18 12:23 ` [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND Stanley.Miao
  0 siblings, 1 reply; 7+ messages in thread
From: Stanley.Miao @ 2010-05-18 12:23 UTC (permalink / raw)
  To: linux-mtd; +Cc: yaffs

Many people encountered this problerm, creating a image by mkyaffs2image,
then write it into a nand falsh with nandwrite, then mounted failed.

This is because mkyaffs2image didn't know the oob layout of a NAND flash,
so it put the yaffs2 tags at the offset 0 of oob area, nandwrite didn't
put it at right position when writing oobdata.

Stanley.

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

* [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND
  2010-05-18 12:23 Fix the bug that nandwrite can't write the yaffs2 image correctly Stanley.Miao
@ 2010-05-18 12:23 ` Stanley.Miao
  2010-05-18 12:23   ` [PATCH 2/2] check if the start address is page-aligned Stanley.Miao
  2010-05-20  2:17   ` [Yaffs] [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND stanley.miao
  0 siblings, 2 replies; 7+ messages in thread
From: Stanley.Miao @ 2010-05-18 12:23 UTC (permalink / raw)
  To: linux-mtd; +Cc: yaffs

The tool mkyaffs2image doesn't know the oob layout of a NAND flash, so it
puts the yaffs2 tags at the offset 0 of oob area, as a result, the image
generated by mkyaffs2image is different with the image dumped by nanddump.
Now adding a parameter "-r" for nandwrite to differentiate these images.

Write a image generated by mkyaffs2image:
$> nandwrite -a -o /dev/mtd3 yaffs2.bin

Write a image dumped by nanddump:
$> nandwrite -a -r /dev/mtd3 image.bin

Signed-off-by: Stanley.Miao <stanley.miao@windriver.com>
---
 nandwrite.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/nandwrite.c b/nandwrite.c
index b77edd6..1e30ad1 100644
--- a/nandwrite.c
+++ b/nandwrite.c
@@ -80,6 +80,7 @@ static void display_help (void)
 "  -m, --markbad           Mark blocks bad if write fails\n"
 "  -n, --noecc             Write without ecc\n"
 "  -o, --oob               Image contains oob data\n"
+"  -r, --raw               Image contains the raw oob data dumped by nanddump\n"
 "  -s addr, --start=addr   Set start address (default is 0)\n"
 "  -p, --pad               Pad to page size\n"
 "  -b, --blockalign=1|2|4  Set multiple of eraseblocks to align to\n"
@@ -110,6 +111,7 @@ static const char	*mtd_device, *img;
 static int		mtdoffset = 0;
 static bool		quiet = false;
 static bool		writeoob = false;
+static bool		rawoob = false;
 static bool		autoplace = false;
 static bool		markbad = false;
 static bool		forcejffs2 = false;
@@ -125,7 +127,7 @@ static void process_options (int argc, char * const argv[])
 
 	for (;;) {
 		int option_index = 0;
-		static const char *short_options = "ab:fjmnopqs:y";
+		static const char *short_options = "ab:fjmnopqrs:y";
 		static const struct option long_options[] = {
 			{"help", no_argument, 0, 0},
 			{"version", no_argument, 0, 0},
@@ -138,6 +140,7 @@ static void process_options (int argc, char * const argv[])
 			{"oob", no_argument, 0, 'o'},
 			{"pad", no_argument, 0, 'p'},
 			{"quiet", no_argument, 0, 'q'},
+			{"raw", no_argument, 0, 'r'},
 			{"start", required_argument, 0, 's'},
 			{"yaffs", no_argument, 0, 'y'},
 			{0, 0, 0, 0},
@@ -187,6 +190,10 @@ static void process_options (int argc, char * const argv[])
 			case 'p':
 				pad = true;
 				break;
+			case 'r':
+				rawoob = true;
+				writeoob = true;
+				break;
 			case 's':
 				mtdoffset = strtol (optarg, NULL, 0);
 				break;
@@ -583,6 +590,7 @@ int main(int argc, char * const argv[])
 				oob.ptr = oobreadbuf;
 			} else {
 				int i, start, len;
+				int tags_pos = 0;
 				/*
 				 *  We use autoplacement and have the oobinfo with the autoplacement
 				 * information from the kernel available
@@ -595,9 +603,13 @@ int main(int argc, char * const argv[])
 						/* Set the reserved bytes to 0xff */
 						start = old_oobinfo.oobfree[i][0];
 						len = old_oobinfo.oobfree[i][1];
-						memcpy(oobbuf + start,
-								oobreadbuf + start,
-								len);
+						if (rawoob)
+							memcpy(oobbuf + start,
+									oobreadbuf + start, len);
+						else
+							memcpy(oobbuf + start,
+									oobreadbuf + tags_pos, len);
+						tags_pos += len;
 					}
 				} else {
 					/* Set at least the ecc byte positions to 0xff */
-- 
1.5.4.3

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

* [PATCH 2/2] check if the start address is page-aligned.
  2010-05-18 12:23 ` [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND Stanley.Miao
@ 2010-05-18 12:23   ` Stanley.Miao
  2010-05-22  5:39     ` Artem Bityutskiy
  2010-05-20  2:17   ` [Yaffs] [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND stanley.miao
  1 sibling, 1 reply; 7+ messages in thread
From: Stanley.Miao @ 2010-05-18 12:23 UTC (permalink / raw)
  To: linux-mtd; +Cc: yaffs

Only page-aligned address is permitted in NAND subsystem.

Signed-off-by: Stanley.Miao <stanley.miao@windriver.com>
---
 nandwrite.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/nandwrite.c b/nandwrite.c
index 1e30ad1..fbb1153 100644
--- a/nandwrite.c
+++ b/nandwrite.c
@@ -306,6 +306,14 @@ int main(int argc, char * const argv[])
 		close(fd);
 		exit (EXIT_FAILURE);
 	}
+	
+	if (mtdoffset & (meminfo.writesize - 1)) {
+		fprintf(stderr, "The start address is not page-aligned !\n"
+				"The pagesize of this NAND Flash is 0x%x.\n",
+				meminfo.writesize);
+		close(fd);
+		exit(EXIT_FAILURE);
+	}
 
 	if (autoplace) {
 		/* Read the current oob info */
-- 
1.5.4.3

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

* Re: [Yaffs] [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND
  2010-05-18 12:23 ` [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND Stanley.Miao
  2010-05-18 12:23   ` [PATCH 2/2] check if the start address is page-aligned Stanley.Miao
@ 2010-05-20  2:17   ` stanley.miao
  2010-05-24  5:51     ` Artem Bityutskiy
  1 sibling, 1 reply; 7+ messages in thread
From: stanley.miao @ 2010-05-20  2:17 UTC (permalink / raw)
  To: Artem.Bityutskiy; +Cc: linux-mtd, yaffs

Hi, Artem,

Any comments ?

Stanley.

Stanley.Miao wrote:
> The tool mkyaffs2image doesn't know the oob layout of a NAND flash, so it
> puts the yaffs2 tags at the offset 0 of oob area, as a result, the image
> generated by mkyaffs2image is different with the image dumped by nanddump.
> Now adding a parameter "-r" for nandwrite to differentiate these images.
>
> Write a image generated by mkyaffs2image:
> $> nandwrite -a -o /dev/mtd3 yaffs2.bin
>
> Write a image dumped by nanddump:
> $> nandwrite -a -r /dev/mtd3 image.bin
>
> Signed-off-by: Stanley.Miao <stanley.miao@windriver.com>
> ---
>  nandwrite.c |   20 ++++++++++++++++----
>  1 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/nandwrite.c b/nandwrite.c
> index b77edd6..1e30ad1 100644
> --- a/nandwrite.c
> +++ b/nandwrite.c
> @@ -80,6 +80,7 @@ static void display_help (void)
>  "  -m, --markbad           Mark blocks bad if write fails\n"
>  "  -n, --noecc             Write without ecc\n"
>  "  -o, --oob               Image contains oob data\n"
> +"  -r, --raw               Image contains the raw oob data dumped by nanddump\n"
>  "  -s addr, --start=addr   Set start address (default is 0)\n"
>  "  -p, --pad               Pad to page size\n"
>  "  -b, --blockalign=1|2|4  Set multiple of eraseblocks to align to\n"
> @@ -110,6 +111,7 @@ static const char	*mtd_device, *img;
>  static int		mtdoffset = 0;
>  static bool		quiet = false;
>  static bool		writeoob = false;
> +static bool		rawoob = false;
>  static bool		autoplace = false;
>  static bool		markbad = false;
>  static bool		forcejffs2 = false;
> @@ -125,7 +127,7 @@ static void process_options (int argc, char * const argv[])
>  
>  	for (;;) {
>  		int option_index = 0;
> -		static const char *short_options = "ab:fjmnopqs:y";
> +		static const char *short_options = "ab:fjmnopqrs:y";
>  		static const struct option long_options[] = {
>  			{"help", no_argument, 0, 0},
>  			{"version", no_argument, 0, 0},
> @@ -138,6 +140,7 @@ static void process_options (int argc, char * const argv[])
>  			{"oob", no_argument, 0, 'o'},
>  			{"pad", no_argument, 0, 'p'},
>  			{"quiet", no_argument, 0, 'q'},
> +			{"raw", no_argument, 0, 'r'},
>  			{"start", required_argument, 0, 's'},
>  			{"yaffs", no_argument, 0, 'y'},
>  			{0, 0, 0, 0},
> @@ -187,6 +190,10 @@ static void process_options (int argc, char * const argv[])
>  			case 'p':
>  				pad = true;
>  				break;
> +			case 'r':
> +				rawoob = true;
> +				writeoob = true;
> +				break;
>  			case 's':
>  				mtdoffset = strtol (optarg, NULL, 0);
>  				break;
> @@ -583,6 +590,7 @@ int main(int argc, char * const argv[])
>  				oob.ptr = oobreadbuf;
>  			} else {
>  				int i, start, len;
> +				int tags_pos = 0;
>  				/*
>  				 *  We use autoplacement and have the oobinfo with the autoplacement
>  				 * information from the kernel available
> @@ -595,9 +603,13 @@ int main(int argc, char * const argv[])
>  						/* Set the reserved bytes to 0xff */
>  						start = old_oobinfo.oobfree[i][0];
>  						len = old_oobinfo.oobfree[i][1];
> -						memcpy(oobbuf + start,
> -								oobreadbuf + start,
> -								len);
> +						if (rawoob)
> +							memcpy(oobbuf + start,
> +									oobreadbuf + start, len);
> +						else
> +							memcpy(oobbuf + start,
> +									oobreadbuf + tags_pos, len);
> +						tags_pos += len;
>  					}
>  				} else {
>  					/* Set at least the ecc byte positions to 0xff */
>   

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

* Re: [PATCH 2/2] check if the start address is page-aligned.
  2010-05-18 12:23   ` [PATCH 2/2] check if the start address is page-aligned Stanley.Miao
@ 2010-05-22  5:39     ` Artem Bityutskiy
  0 siblings, 0 replies; 7+ messages in thread
From: Artem Bityutskiy @ 2010-05-22  5:39 UTC (permalink / raw)
  To: Stanley.Miao; +Cc: linux-mtd, yaffs

On Tue, 2010-05-18 at 20:23 +0800, Stanley.Miao wrote:
> Only page-aligned address is permitted in NAND subsystem.
> 
> Signed-off-by: Stanley.Miao <stanley.miao@windriver.com>

Pushed both patches to the mtd-utils repo, thanks. However, I had to fix
a tiny white-space damage for you:

Applying: nandwrite: check if the start address is page-aligned.
/home/dedekind/git/mtd-utils/.git/rebase-apply/patch:13: trailing
whitespace.

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

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

* Re: [Yaffs] [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND
  2010-05-20  2:17   ` [Yaffs] [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND stanley.miao
@ 2010-05-24  5:51     ` Artem Bityutskiy
  2010-05-24  6:21       ` stanley.miao
  0 siblings, 1 reply; 7+ messages in thread
From: Artem Bityutskiy @ 2010-05-24  5:51 UTC (permalink / raw)
  To: stanley.miao; +Cc: Artem.Bityutskiy, linux-mtd, yaffs

On Thu, 2010-05-20 at 10:17 +0800, stanley.miao wrote:
> Hi, Artem,
> 
> Any comments ?
> 
> Stanley.

Sorry, but what else kind of comments would you like to see in addition
to these:

http://lists.infradead.org/pipermail/linux-mtd/2010-May/030280.html

?

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

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

* Re: [Yaffs] [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND
  2010-05-24  5:51     ` Artem Bityutskiy
@ 2010-05-24  6:21       ` stanley.miao
  0 siblings, 0 replies; 7+ messages in thread
From: stanley.miao @ 2010-05-24  6:21 UTC (permalink / raw)
  To: dedekind1; +Cc: Artem.Bityutskiy, linux-mtd, yaffs

Sorry, I didn't receive your email. There must be some problems with our 
mail server.

Stanley.

Artem Bityutskiy wrote:
> On Thu, 2010-05-20 at 10:17 +0800, stanley.miao wrote:
>   
>> Hi, Artem,
>>
>> Any comments ?
>>
>> Stanley.
>>     
>
> Sorry, but what else kind of comments would you like to see in addition
> to these:
>
> http://lists.infradead.org/pipermail/linux-mtd/2010-May/030280.html
>
> ?
>
>   

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

end of thread, other threads:[~2010-05-24  6:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-18 12:23 Fix the bug that nandwrite can't write the yaffs2 image correctly Stanley.Miao
2010-05-18 12:23 ` [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND Stanley.Miao
2010-05-18 12:23   ` [PATCH 2/2] check if the start address is page-aligned Stanley.Miao
2010-05-22  5:39     ` Artem Bityutskiy
2010-05-20  2:17   ` [Yaffs] [PATCH 1/2] Fix the bug of writing a yaffs2 image to NAND stanley.miao
2010-05-24  5:51     ` Artem Bityutskiy
2010-05-24  6:21       ` stanley.miao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.