Skip to contentSkip to conversation

nandtest: use new pread and pwrite functions

PATCH Applied Alexander Aring 2 participants 4 messages Feb 19, 2013 – Feb 21, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 nandtest: use new pread and pwrite functions

---
 commands/nandtest.c | 36 ++++++------------------------------
 1 file changed, 6 insertions(+), 30 deletions(-)
commands/nandtest.c +6 -30
index f08f8eb..4e6024b 100644
@@ -43,41 +43,17 @@ static unsigned int ecc_stats_over;
 static unsigned int ecc_failed_cnt;
 
 /*
- * Implementation of pread with lseek and read.
- */
-static ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
-{
-	int ret;
-
-	/* Seek to offset */
-	ret = lseek(fd, offset, SEEK_SET);
-	if (ret < 0)
-		perror("lseek");
-
-	/* Read from flash and put it into buf  */
-	ret = read(fd, buf, count);
-	if (ret < 0)
-		perror("read");
-
-	return 0;
-}
-
-/*
  * Implementation of pwrite with lseek and write.
  */
-static ssize_t pwrite(int fd, const void *buf,
+static ssize_t __pwrite(int fd, const void *buf,
 		size_t count, loff_t offset, loff_t length)
 {
-	int ret;
-
-	ret = lseek(fd, offset, SEEK_SET);
-	if (ret < 0)
-		perror("lseek");
+	ssize_t ret;
 
 	/* Write buf to flash */
-	ret = write(fd, buf, count);
+	ret = pwrite(fd, buf, count, offset);
 	if (ret < 0) {
-		perror("write");
+		perror("pwrite");
 		if (markbad) {
 			printf("\nMark block bad at 0x%08llx\n",
 					offset + memregion.offset);
@@ -88,7 +64,7 @@ static ssize_t pwrite(int fd, const void *buf,
 	}
 
 	flush(fd);
-	return 0;
+	return ret;
 }
 
 /*
@@ -119,7 +95,7 @@ static int erase_and_write(loff_t ofs, unsigned char *data,
 	for (i = 0; i < meminfo.erasesize;
 			i += meminfo.writesize) {
 		/* Write data to given offset */
-		pwrite(fd, data + i, meminfo.writesize,
+		__pwrite(fd, data + i, meminfo.writesize,
 				ofs + i, length);
 
 		/* Read data from offset */
Signature · 7 lines
1.8.1.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/2 nandtest: fix length calculation

---
 commands/nandtest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
commands/nandtest.c +4 -4
index 4e6024b..ba15ecf 100644
@@ -112,7 +112,7 @@ static int erase_and_write(loff_t ofs, unsigned char *data,
 					newstats.corrected - oldstats.corrected,
 					ofs + memregion.offset + i);
 			init_progression_bar(length);
-			show_progress(ofs);
+			show_progress(ofs + i);
 			if ((newstats.corrected-oldstats.corrected) >=
 					MAX_ECC_BITS) {
 				/* Increment ECC stats that
@@ -130,7 +130,7 @@ static int erase_and_write(loff_t ofs, unsigned char *data,
 			printf("\nECC failed at page 0x%08llx\n",
 					ofs + memregion.offset + i);
 			init_progression_bar(length);
-			show_progress(ofs);
+			show_progress(ofs + i);
 			oldstats.failed = newstats.failed;
 			ecc_failed_cnt++;
 		}
@@ -292,8 +292,8 @@ static int do_nandtest(int argc, char *argv[])
 
 	for (iter = 0; iter < nr_iterations; iter++) {
 		init_progression_bar(length);
-		for (test_ofs = flash_offset;
-				test_ofs < flash_offset + length;
+		for (test_ofs = 0;
+				test_ofs < length;
 				test_ofs += meminfo.erasesize) {
 			show_progress(test_ofs);
 			srand(seed);
Signature · 7 lines
1.8.1.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#2 lore raw
In reply to Alexander Aring
Quoted 4 lines · Alexander Aring
---
 commands/nandtest.c | 36 ++++++------------------------------
 1 file changed, 6 insertions(+), 30 deletions(-)

Applied, thanks

I squashed this into the commit adding pread/pwrite to make this commit compilable.

Sascha

Quoted 78 lines
commands/nandtest.c +6 -30
index f08f8eb..4e6024b 100644
@@ -43,41 +43,17 @@ static unsigned int ecc_stats_over;
 static unsigned int ecc_failed_cnt;
 
 /*
- * Implementation of pread with lseek and read.
- */
-static ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
-{
-	int ret;
-
-	/* Seek to offset */
-	ret = lseek(fd, offset, SEEK_SET);
-	if (ret < 0)
-		perror("lseek");
-
-	/* Read from flash and put it into buf  */
-	ret = read(fd, buf, count);
-	if (ret < 0)
-		perror("read");
-
-	return 0;
-}
-
-/*
  * Implementation of pwrite with lseek and write.
  */
-static ssize_t pwrite(int fd, const void *buf,
+static ssize_t __pwrite(int fd, const void *buf,
 		size_t count, loff_t offset, loff_t length)
 {
-	int ret;
-
-	ret = lseek(fd, offset, SEEK_SET);
-	if (ret < 0)
-		perror("lseek");
+	ssize_t ret;
 
 	/* Write buf to flash */
-	ret = write(fd, buf, count);
+	ret = pwrite(fd, buf, count, offset);
 	if (ret < 0) {
-		perror("write");
+		perror("pwrite");
 		if (markbad) {
 			printf("\nMark block bad at 0x%08llx\n",
 					offset + memregion.offset);
@@ -88,7 +64,7 @@ static ssize_t pwrite(int fd, const void *buf,
 	}
 
 	flush(fd);
-	return 0;
+	return ret;
 }
 
 /*
@@ -119,7 +95,7 @@ static int erase_and_write(loff_t ofs, unsigned char *data,
 	for (i = 0; i < meminfo.erasesize;
 			i += meminfo.writesize) {
 		/* Write data to given offset */
-		pwrite(fd, data + i, meminfo.writesize,
+		__pwrite(fd, data + i, meminfo.writesize,
 				ofs + i, length);
 
 		/* Read data from offset */
Signature · 7 lines
1.8.1.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Hi,

Quoted 11 lines · Sascha Hauer
Quoted 4 lines · Alexander Aring
---
 commands/nandtest.c | 36 ++++++------------------------------
 1 file changed, 6 insertions(+), 30 deletions(-)

Applied, thanks

I squashed this into the commit adding pread/pwrite to make this commit compilable.

Thanks. :-)

Regards
Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox