Skip to contentSkip to conversation

NAND feature update

PATCH New Ladislav Michl 3 participants 5 messages Aug 20, 2006 – Oct 23, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NAND feature update

Wolfgang,

this patch implements functionaly I found useful to have and hopefuly others can benefit from it too. Please drop all my previous NAND related, not yet applied patches. Once (if) applied I will rediff the rest.

Now you can do:

# mtdparts
[snip]
device nand0 <omapnand.0>, # parts = 5
 #: name                        size            offset          mask_flags
 0: kernel0                     0x00400000      0x00000000      0
 1: rootfs0                     0x02800000      0x00400000      0
 2: kernel1                     0x00400000      0x02c00000      0
 3: rootfs1                     0x02800000      0x03000000      0
 4: data                        0x02800000      0x05800000      0
# nand write 10400000 kernel1 100000
NAND write: device 0 offset 0x2c00000, size 0x100000  1048576 bytes written: OK
# nboot kernel0
Loading from NAND 128MiB 3,3V 8-bit, offset 0x0
...
# nand era kernel1
NAND erase: device 0 offset 0x2c00000, size 0x400000 OK

or

# nand era nand0,2
NAND erase: device 0 offset 0x2c00000, size 0x400000 OK
# chpart rootfs1
partition changed to nand0,3
# fsload /boot/uImage
### JFFS2 loading '/boot/uImage' to 0x10400000
...

etc...

Best regards,
ladis

CHANGELOG
* Patch by Ladislav Michl, 18 Aug 2006:
chpart, nboot and NAND subsystem related commands now accept also partition name to specify offset.

common/cmd_jffs2.c +13 -1
index 201c3c1..90b2930 100644
@@ -1300,7 +1303,7 @@ static void list_partitions(void)
  * Given partition identifier in form of <dev_type><dev_num>,<part_num> find
  * corresponding device and verify partition number.
  *
- * @param id string describing device and partition
+ * @param id string describing device and partition or partition name
  * @param dev pointer to the requested device (output)
  * @param part_num verified partition number (output)
  * @param part pointer to requested partition (output)
@@ -1309,11 +1312,23 @@ static void list_partitions(void)
 int find_dev_and_part(const char *id, struct mtd_device **dev,
 		u8 *part_num, struct part_info **part)
 {
+	struct list_head *dentry, *pentry;
 	u8 type, dnum, pnum;
 	const char *p;
 
 	DEBUGF("--- find_dev_and_part ---\nid = %s\n", id);
 
+	list_for_each(dentry, &devices) {
+		*part_num = 0;
+		*dev = list_entry(dentry, struct mtd_device, link);
+		list_for_each(pentry, &(*dev)->parts) {
+			*part = list_entry(pentry, struct part_info, link);
+			if (strcmp((*part)->name, id) == 0)
+				return 0;
+			(*part_num)++;
+		}
+	}
+
 	p = id;
 	*dev = NULL;
 	*part = NULL;
common/cmd_nand.c +165 -103

347 lines not on this page · raw message

doc/README.nand +17 -12
index f2d6a5b..a2d10db 100644
@@ -36,14 +36,19 @@ Commands:
    nand device num
       Make device `num' the current device and print information about it.
 
-   nand erase off size
-   nand erase clean [off size]
-      Erase `size' bytes starting at offset `off'.  Only complete erase
-      blocks can be erased.
+   nand erase off|partition size
+   nand erase clean [off|partition size]
+      Erase `size' bytes starting at offset `off'. Alternatively partition
+      name can be specified, in this case size will be eventually limited
+      to not exceed partition size (this behaviour applies also to read
+      and write commands). Only complete erase blocks can be erased.
+
+      If `erase' is specified without an offset or size, the entire flash
+      is erased. If `erase' is specified with partition but without an
+      size, the entire partition is erased.
 
       If `clean' is specified, a JFFS2-style clean marker is written to
-      each block after it is erased. If `clean' is specified without an
-      offset or size, the entire flash is erased.
+      each block after it is erased.
 
       This command will not erase blocks that are marked bad. There is
       a debug option in cmd_nand.c to allow bad blocks to be erased.
@@ -53,28 +58,28 @@ Commands:
    nand info
       Print information about all of the NAND devices found.
 
-   nand read addr ofs size
+   nand read addr ofs|partition size
       Read `size' bytes from `ofs' in NAND flash to `addr'. If a page
       cannot be read because it is marked bad or an uncorrectable data
       error is found the command stops with an error.
 
-   nand read.jffs2 addr ofs size
+   nand read.jffs2 addr ofs|partition size
       Like `read', but the data for blocks that are marked bad is read as
       0xff. This gives a readable JFFS2 image that can be processed by
       the JFFS2 commands such as ls and fsload.
 
-   nand read.oob addr ofs size
+   nand read.oob addr ofs|partition size
       Read `size' bytes from the out-of-band data area corresponding to
       `ofs' in NAND flash to `addr'. This is limited to the 16 bytes of
       data for one 512-byte page or 2 256-byte pages. There is no check
       for bad blocks or ECC errors.
 
-   nand write addr ofs size
+   nand write addr ofs|partition size
       Write `size' bytes from `addr' to `ofs' in NAND flash. If a page
       cannot be written because it is marked bad or the write fails the
       command stops with an error.
 
-   nand write.jffs2 addr ofs size
+   nand write.jffs2 addr ofs|partition size
       Like `write', but blocks that are marked bad are skipped and the
       is written to the next block instead. This allows writing writing
       a JFFS2 image, as long as the image is short enough to fit even
@@ -82,7 +87,7 @@ Commands:
       produced by mkfs.jffs2 should work well, but loading an image copied
       from another flash is going to be trouble if there are any bad blocks.
 
-   nand write.oob addr ofs size
+   nand write.oob addr ofs|partition size
       Write `size' bytes from `addr' to the out-of-band data area
       corresponding to `ofs' in NAND flash. This is limited to the 16 bytes
       of data for one 512-byte page or 2 256-byte pages. There is no check
#1 lore raw

PATCH 1/1 NAND feature update

Here is updated patch, regenerated against top of git tree. Please give it a try.

CHANGELOG
* Patch by Ladislav Michl, 19 Oct 2006:
chpart, nboot and NAND subsystem related commands now accept also partition name to specify offset.

common/cmd_jffs2.c +13 -1
index b5fd417..3935345 100644
@@ -1300,7 +1303,7 @@ static void list_partitions(void)
  * Given partition identifier in form of <dev_type><dev_num>,<part_num> find
  * corresponding device and verify partition number.
  *
- * @param id string describing device and partition
+ * @param id string describing device and partition or partition name
  * @param dev pointer to the requested device (output)
  * @param part_num verified partition number (output)
  * @param part pointer to requested partition (output)
@@ -1309,11 +1312,23 @@ static void list_partitions(void)
 int find_dev_and_part(const char *id, struct mtd_device **dev,
 		u8 *part_num, struct part_info **part)
 {
+	struct list_head *dentry, *pentry;
 	u8 type, dnum, pnum;
 	const char *p;
 
 	DEBUGF("--- find_dev_and_part ---\nid = %s\n", id);
 
+	list_for_each(dentry, &devices) {
+		*part_num = 0;
+		*dev = list_entry(dentry, struct mtd_device, link);
+		list_for_each(pentry, &(*dev)->parts) {
+			*part = list_entry(pentry, struct part_info, link);
+			if (strcmp((*part)->name, id) == 0)
+				return 0;
+			(*part_num)++;
+		}
+	}
+
 	p = id;
 	*dev = NULL;
 	*part = NULL;
common/cmd_nand.c +184 -155

454 lines not on this page · raw message

doc/README.nand +17 -12
index 5279a4f..b5171f4 100644
@@ -34,14 +34,19 @@ Commands:
    nand device num
       Make device `num' the current device and print information about it.
 
-   nand erase off size
-   nand erase clean [off size]
-      Erase `size' bytes starting at offset `off'.  Only complete erase
-      blocks can be erased.
+   nand erase off|partition size
+   nand erase clean [off|partition size]
+      Erase `size' bytes starting at offset `off'. Alternatively partition
+      name can be specified, in this case size will be eventually limited
+      to not exceed partition size (this behaviour applies also to read
+      and write commands). Only complete erase blocks can be erased.
+
+      If `erase' is specified without an offset or size, the entire flash
+      is erased. If `erase' is specified with partition but without an
+      size, the entire partition is erased.
 
       If `clean' is specified, a JFFS2-style clean marker is written to
-      each block after it is erased. If `clean' is specified without an
-      offset or size, the entire flash is erased.
+      each block after it is erased.
 
       This command will not erase blocks that are marked bad. There is
       a debug option in cmd_nand.c to allow bad blocks to be erased.
@@ -51,28 +56,28 @@ Commands:
    nand info
       Print information about all of the NAND devices found.
 
-   nand read addr ofs size
+   nand read addr ofs|partition size
       Read `size' bytes from `ofs' in NAND flash to `addr'. If a page
       cannot be read because it is marked bad or an uncorrectable data
       error is found the command stops with an error.
 
-   nand read.jffs2 addr ofs size
+   nand read.jffs2 addr ofs|partition size
       Like `read', but the data for blocks that are marked bad is read as
       0xff. This gives a readable JFFS2 image that can be processed by
       the JFFS2 commands such as ls and fsload.
 
-   nand read.oob addr ofs size
+   nand read.oob addr ofs|partition size
       Read `size' bytes from the out-of-band data area corresponding to
       `ofs' in NAND flash to `addr'. This is limited to the 16 bytes of
       data for one 512-byte page or 2 256-byte pages. There is no check
       for bad blocks or ECC errors.
 
-   nand write addr ofs size
+   nand write addr ofs|partition size
       Write `size' bytes from `addr' to `ofs' in NAND flash. If a page
       cannot be written because it is marked bad or the write fails the
       command stops with an error.
 
-   nand write.jffs2 addr ofs size
+   nand write.jffs2 addr ofs|partition size
       Like `write', but blocks that are marked bad are skipped and the
       is written to the next block instead. This allows writing writing
       a JFFS2 image, as long as the image is short enough to fit even
@@ -80,7 +85,7 @@ Commands:
       produced by mkfs.jffs2 should work well, but loading an image copied
       from another flash is going to be trouble if there are any bad blocks.
 
-   nand write.oob addr ofs size
+   nand write.oob addr ofs|partition size
       Write `size' bytes from `addr' to the out-of-band data area
       corresponding to `ofs' in NAND flash. This is limited to the 16 bytes
       of data for one 512-byte page or 2 256-byte pages. There is no check
drivers/nand/nand_util.c +2 -9
index 7570210..10bf036 100644
@@ -83,15 +83,8 @@ int nand_erase_opts(nand_info_t *meminfo
 
 	erase.mtd = meminfo;
 	erase.len  = meminfo->erasesize;
-	if (opts->offset == 0 && opts->length == 0) {
-		/* erase complete chip */
-		erase.addr = 0;
-		erase_length = meminfo->size;
-	} else {
-		/* erase specified region */
-		erase.addr = opts->offset;
-		erase_length = opts->length;
-	}
+	erase.addr = opts->offset;
+	erase_length = opts->length;
 
 	isNAND = meminfo->type == MTD_NANDFLASH ? 1 : 0;
 
#2 lore raw

PATCH 1/1 NAND feature update

Hi Ladis,

Quoted 4 lines · Ladislav Michl

Here is updated patch, regenerated against top of git tree. Please give it a try.

Does not apply clean anymore. Could you please fix this and resubmit. Thanks.

And here already some comments:

<snip>

common/cmd_nand.c static int nand_dump(nand_info_t *nand, · line 95

Quoted 7 lines
common/cmd_nand.c +1 -2
@@ -83,50 +92,70 @@ static int nand_dump(nand_info_t *nand, 
 
 /* ------------------------------------------------------------------------- */
 
-static void
-arg_off_size(int argc, char *argv[], ulong *off, ulong *size, ulong totsize)
+static int str2long(char *p, ulong *num)

Please either remove this small helper function are make it inline.

<snip>

common/cmd_nand.c int do_nand(cmd_tbl_t * cmdtp, int flag, · line 213

Quoted 6 lines
common/cmd_nand.c +1 -1
@@ -181,7 +210,7 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
 		return 0;
 	}
 
-	if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0 &&
+	if (strcmp(cmd, "bad") != 0 && strncmp(cmd, "erase", 3) != 0 &&

Please don't change the check on "erase" here. The string should match completely and not only the first 3 chars.

common/cmd_nand.c int do_nand(cmd_tbl_t * cmdtp, int flag, · line 237

Quoted 9 lines
common/cmd_nand.c +1 -1
 	    strncmp(cmd, "dump", 4) != 0 &&
 	    strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0 &&
 	    strcmp(cmd, "scrub") != 0 && strcmp(cmd, "markbad") != 0 &&
@@ -205,35 +234,15 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
 		return 0;
 	}
 
-	if (strcmp(cmd, "erase") == 0 || strcmp(cmd, "scrub") == 0) {
+	if (strncmp(cmd, "erase", 3) == 0 || strcmp(cmd, "scrub") == 0) {

Again.

Quoted 22 lines
common/cmd_nand.c +1 -17
 		nand_erase_options_t opts;
 		int clean = argc >= 3 && !strcmp("clean", argv[2]);
-		int rest_argc = argc - 2;
-		char **rest_argv = argv + 2;
+		int o = clean ? 3 : 2;
 		int scrub = !strcmp(cmd, "scrub");
 
-		if (clean) {
-			rest_argc--;
-			rest_argv++;
-		}
-
-		if (rest_argc == 0) {
-
-			printf("\nNAND %s: device %d whole chip\n",
-			       cmd,
-			       nand_curr_device);
-
-			off = size = 0;
-		} else {
-			arg_off_size(rest_argc, rest_argv, &off, &size,
-				     nand->size);

common/cmd_nand.c int do_nand(cmd_tbl_t * cmdtp, int flag, · line 245

Quoted 10 lines
common/cmd_nand.c +3 -7
-
-			if (off == 0 && size == 0)
-				return 1;
-
-			printf("\nNAND %s: device %d offset 0x%x, size 0x%x\n",
-			       cmd, nand_curr_device, off, size);
-		}
+		printf("\nNAND %s: ", scrub ? "scrub" : "erase");
+		if (arg_off_size(argc - o, argv + o, nand, &off, &size) != 0)
+			return 1;

This seems quite obscure (at least to Wolfgang and me ;-)). Could you please either make the code a little more "readable", or at least add some comments here. Thanks.

Quoted 21 lines
common/cmd_nand.c +2 -12
 		memset(&opts, 0, sizeof(opts));
 		opts.offset = off;
@@ -242,23 +251,23 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
 		opts.quiet  = quiet;
 
 		if (scrub) {
-			printf("Warning: "
-			       "scrub option will erase all factory set "
-			       "bad blocks!\n"
-			       "	 "
-			       "There is no reliable way to recover them.\n"
-			       "	 "
-			       "Use this command only for testing purposes "
-			       "if you\n"
-			       "	 "
-			       "are sure of what you are doing!\n"
-			       "\nReally scrub this NAND flash? <y/N>\n"
-				);
+			puts("Warning: "
+			     "scrub option will erase all factory set "

common/cmd_nand.c int do_nand(cmd_tbl_t * cmdtp, int flag, · line 265

Quoted 10 lines
common/cmd_nand.c +10 -0
+			     "bad blocks!\n"
+			     "         "
+			     "There is no reliable way to recover them.\n"
+			     "         "
+			     "Use this command only for testing purposes "
+			     "if you\n"
+			     "         "
+			     "are sure of what you are doing!\n"
+			     "\nReally scrub this NAND flash? <y/N>\n"
+			    );

Indentation with TAB's please.

<snip>

common/cmd_nand.c int do_nand(cmd_tbl_t * cmdtp, int flag, · line 413

Quoted 9 lines
common/cmd_nand.c +2 -2
@@ -404,9 +408,9 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
 		       }
 		} else {
 			if (!nand_lock(nand, tight)) {
-				printf ("NAND flash successfully locked\n");
+				puts("NAND flash successfully locked\n");
 			} else {
-				printf ("Error locking NAND flash. \n");
+				puts("Error locking NAND flash. \n");

Please remove the space after the ".". Thanks.

Quoted 14 lines
common/cmd_nand.c +0 -7
 				return 1;
 			}
 		}
@@ -414,19 +418,14 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
 	}
 
 	if (strcmp(cmd, "unlock") == 0) {
-		if (argc == 2) {
-			off = 0;
-			size = nand->size;
-		} else {
-			arg_off_size(argc - 2, argv + 2, &off, &size,
-				     nand->size);
-		}

common/cmd_nand.c int do_nand(cmd_tbl_t * cmdtp, int flag, · line 427

Quoted 10 lines
common/cmd_nand.c +4 -3
+		if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0)
+			return 1;
 
 		if (!nand_unlock(nand, off, size)) {
-			printf("NAND flash successfully unlocked\n");
+			puts("NAND flash successfully unlocked\n");
 		} else {
-			printf("Error unlocking NAND flash. "
-			       "Write and erase will probably fail\n");
+			puts("Error unlocking NAND flash. "

Please remove the space after the ".". Thanks.

Best regards,
Stefan

#3 lore raw

PATCH 1/1 NAND feature update

Quoted 4 lines · In message <[email protected]> Stefan Roese wrote:

common/cmd_nand.c int do_nand(cmd_tbl_t * cmdtp, int flag, · line 413

Quoted 2 lines
common/cmd_nand.c +1 -0
+				puts("Error locking NAND flash. \n");

Please remove the space after the ".". Thanks.

And the dot, too.

Quoted 3 lines

common/cmd_nand.c int do_nand(cmd_tbl_t * cmdtp, int flag, · line 427

Quoted 1 line
common/cmd_nand.c +1 -0
+			puts("Error unlocking NAND flash. "

Please remove the space after the ".". Thanks.

Same here. Thanks.

Best regards,

Wolfgang Denk

Signature · 3 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.
#4 lore raw

PATCH 1/1 NAND feature update

In reply to Stefan Roese

Hi Stefan,

Quoted 9 lines · Stefan Roese

Review static int nand_dump(nand_info_t *nand, · line 95

Quoted 7 lines
(quoted diff) +1 -2
@@ -83,50 +92,70 @@ static int nand_dump(nand_info_t *nand, 
 
 /* ------------------------------------------------------------------------- */
 
-static void
-arg_off_size(int argc, char *argv[], ulong *off, ulong *size, ulong totsize)
+static int str2long(char *p, ulong *num)

Please either remove this small helper function are make it inline.

Marked inline.

Quoted 9 lines

Review int do_nand(cmd_tbl_t * cmdtp, int flag, · line 213

Quoted 6 lines
(quoted diff) +1 -1
@@ -181,7 +210,7 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
 		return 0;
 	}
 
-	if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0 &&
+	if (strcmp(cmd, "bad") != 0 && strncmp(cmd, "erase", 3) != 0 &&

Please don't change the check on "erase" here. The string should match completely and not only the first 3 chars.

Change removed (I wanted to save myself some typing and make it the same as erase (era) command).

Quoted 28 lines
Quoted 28 lines
(quoted diff) +1 -23
 		nand_erase_options_t opts;
 		int clean = argc >= 3 && !strcmp("clean", argv[2]);
-		int rest_argc = argc - 2;
-		char **rest_argv = argv + 2;
+		int o = clean ? 3 : 2;
 		int scrub = !strcmp(cmd, "scrub");
 
-		if (clean) {
-			rest_argc--;
-			rest_argv++;
-		}
-
-		if (rest_argc == 0) {
-
-			printf("\nNAND %s: device %d whole chip\n",
-			       cmd,
-			       nand_curr_device);
-
-			off = size = 0;
-		} else {
-			arg_off_size(rest_argc, rest_argv, &off, &size,
-				     nand->size);
-
-			if (off == 0 && size == 0)
-				return 1;
-
-			printf("\nNAND %s: device %d offset 0x%x, size 0x%x\n",
-			       cmd, nand_curr_device, off, size);
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +3 -1
-		}
+		printf("\nNAND %s: ", scrub ? "scrub" : "erase");
+		if (arg_off_size(argc - o, argv + o, nand, &off, &size) != 0)
+			return 1;

This seems quite obscure (at least to Wolfgang and me ;-)). Could you please either make the code a little more "readable", or at least add some comments here. Thanks.

Yes, we already had that debate, but I forgot to add comments to this patch. Readded.

Quoted 25 lines
Quoted 25 lines
(quoted diff) +6 -12
 		memset(&opts, 0, sizeof(opts));
 		opts.offset = off;
@@ -242,23 +251,23 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
 		opts.quiet  = quiet;
 
 		if (scrub) {
-			printf("Warning: "
-			       "scrub option will erase all factory set "
-			       "bad blocks!\n"
-			       "	 "
-			       "There is no reliable way to recover them.\n"
-			       "	 "
-			       "Use this command only for testing purposes "
-			       "if you\n"
-			       "	 "
-			       "are sure of what you are doing!\n"
-			       "\nReally scrub this NAND flash? <y/N>\n"
-				);
+			puts("Warning: "
+			     "scrub option will erase all factory set "
+			     "bad blocks!\n"
+			     "         "
+			     "There is no reliable way to recover them.\n"
+			     "         "
Quoted 8 lines

Review int do_nand(cmd_tbl_t * cmdtp, int flag, · line 265

Quoted 6 lines
(quoted diff) +6 -0
+			     "Use this command only for testing purposes "
+			     "if you\n"
+			     "         "
+			     "are sure of what you are doing!\n"
+			     "\nReally scrub this NAND flash? <y/N>\n"
+			    );

Indentation with TAB's please.

Indenting with TABs really doesn't improve readability. Original code uses this style indentation, so I kept it. Anyway, I can send it as separate patch to make it consistent over whole file.

Quoted 11 lines

Review int do_nand(cmd_tbl_t * cmdtp, int flag, · line 413

Quoted 9 lines
(quoted diff) +2 -2
@@ -404,9 +408,9 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
 		       }
 		} else {
 			if (!nand_lock(nand, tight)) {
-				printf ("NAND flash successfully locked\n");
+				puts("NAND flash successfully locked\n");
 			} else {
-				printf ("Error locking NAND flash. \n");
+				puts("Error locking NAND flash. \n");

Please remove the space after the ".". Thanks.

Fixed.

Quoted 14 lines
Quoted 14 lines
(quoted diff) +2 -7
@@ -414,19 +418,14 @@ int do_nand(cmd_tbl_t * cmdtp, int flag,
 	}
 
 	if (strcmp(cmd, "unlock") == 0) {
-		if (argc == 2) {
-			off = 0;
-			size = nand->size;
-		} else {
-			arg_off_size(argc - 2, argv + 2, &off, &size,
-				     nand->size);
-		}
+		if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0)
+			return 1;
 
Quoted 9 lines

Review int do_nand(cmd_tbl_t * cmdtp, int flag, · line 427

Quoted 7 lines
(quoted diff) +2 -3
 		if (!nand_unlock(nand, off, size)) {
-			printf("NAND flash successfully unlocked\n");
+			puts("NAND flash successfully unlocked\n");
 		} else {
-			printf("Error unlocking NAND flash. "
-			       "Write and erase will probably fail\n");
+			puts("Error unlocking NAND flash. "

Please remove the space after the ".". Thanks.

This is multiline string. "... NAND flash. Write and..." reads better with space.

Here is an updated patch.

CHANGELOG
* Patch by Ladislav Michl, 23 Oct 2006:
chpart, nboot and NAND subsystem related commands now accept also partition name to specify offset.

common/cmd_jffs2.c +13 -1
index b5fd417..7fd1fa3 100644
@@ -1300,7 +1300,7 @@ static void list_partitions(void)
  * Given partition identifier in form of <dev_type><dev_num>,<part_num> find
  * corresponding device and verify partition number.
  *
- * @param id string describing device and partition
+ * @param id string describing device and partition or partition name
  * @param dev pointer to the requested device (output)
  * @param part_num verified partition number (output)
  * @param part pointer to requested partition (output)
@@ -1309,11 +1309,23 @@ static void list_partitions(void)
 int find_dev_and_part(const char *id, struct mtd_device **dev,
 		u8 *part_num, struct part_info **part)
 {
+	struct list_head *dentry, *pentry;
 	u8 type, dnum, pnum;
 	const char *p;
 
 	DEBUGF("--- find_dev_and_part ---\nid = %s\n", id);
 
+	list_for_each(dentry, &devices) {
+		*part_num = 0;
+		*dev = list_entry(dentry, struct mtd_device, link);
+		list_for_each(pentry, &(*dev)->parts) {
+			*part = list_entry(pentry, struct part_info, link);
+			if (strcmp((*part)->name, id) == 0)
+				return 0;
+			(*part_num)++;
+		}
+	}
+
 	p = id;
 	*dev = NULL;
 	*part = NULL;
common/cmd_nand.c +190 -154

453 lines not on this page · raw message

doc/README.nand +17 -12
index 5279a4f..b5171f4 100644
@@ -34,14 +34,19 @@ Commands:
    nand device num
       Make device `num' the current device and print information about it.
 
-   nand erase off size
-   nand erase clean [off size]
-      Erase `size' bytes starting at offset `off'.  Only complete erase
-      blocks can be erased.
+   nand erase off|partition size
+   nand erase clean [off|partition size]
+      Erase `size' bytes starting at offset `off'. Alternatively partition
+      name can be specified, in this case size will be eventually limited
+      to not exceed partition size (this behaviour applies also to read
+      and write commands). Only complete erase blocks can be erased.
+
+      If `erase' is specified without an offset or size, the entire flash
+      is erased. If `erase' is specified with partition but without an
+      size, the entire partition is erased.
 
       If `clean' is specified, a JFFS2-style clean marker is written to
-      each block after it is erased. If `clean' is specified without an
-      offset or size, the entire flash is erased.
+      each block after it is erased.
 
       This command will not erase blocks that are marked bad. There is
       a debug option in cmd_nand.c to allow bad blocks to be erased.
@@ -51,28 +56,28 @@ Commands:
    nand info
       Print information about all of the NAND devices found.
 
-   nand read addr ofs size
+   nand read addr ofs|partition size
       Read `size' bytes from `ofs' in NAND flash to `addr'. If a page
       cannot be read because it is marked bad or an uncorrectable data
       error is found the command stops with an error.
 
-   nand read.jffs2 addr ofs size
+   nand read.jffs2 addr ofs|partition size
       Like `read', but the data for blocks that are marked bad is read as
       0xff. This gives a readable JFFS2 image that can be processed by
       the JFFS2 commands such as ls and fsload.
 
-   nand read.oob addr ofs size
+   nand read.oob addr ofs|partition size
       Read `size' bytes from the out-of-band data area corresponding to
       `ofs' in NAND flash to `addr'. This is limited to the 16 bytes of
       data for one 512-byte page or 2 256-byte pages. There is no check
       for bad blocks or ECC errors.
 
-   nand write addr ofs size
+   nand write addr ofs|partition size
       Write `size' bytes from `addr' to `ofs' in NAND flash. If a page
       cannot be written because it is marked bad or the write fails the
       command stops with an error.
 
-   nand write.jffs2 addr ofs size
+   nand write.jffs2 addr ofs|partition size
       Like `write', but blocks that are marked bad are skipped and the
       is written to the next block instead. This allows writing writing
       a JFFS2 image, as long as the image is short enough to fit even
@@ -80,7 +85,7 @@ Commands:
       produced by mkfs.jffs2 should work well, but loading an image copied
       from another flash is going to be trouble if there are any bad blocks.
 
-   nand write.oob addr ofs size
+   nand write.oob addr ofs|partition size
       Write `size' bytes from `addr' to the out-of-band data area
       corresponding to `ofs' in NAND flash. This is limited to the 16 bytes
       of data for one 512-byte page or 2 256-byte pages. There is no check
drivers/nand/nand_util.c +2 -9
index 7570210..10bf036 100644
@@ -83,15 +83,8 @@ int nand_erase_opts(nand_info_t *meminfo
 
 	erase.mtd = meminfo;
 	erase.len  = meminfo->erasesize;
-	if (opts->offset == 0 && opts->length == 0) {
-		/* erase complete chip */
-		erase.addr = 0;
-		erase_length = meminfo->size;
-	} else {
-		/* erase specified region */
-		erase.addr = opts->offset;
-		erase_length = opts->length;
-	}
+	erase.addr = opts->offset;
+	erase_length = opts->length;
 
 	isNAND = meminfo->type == MTD_NANDFLASH ? 1 : 0;