public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH mtd-utils] nandwrite: warn about writing 0xff blocks
@ 2022-03-25 12:00 Rafał Miłecki
  2022-03-28  6:51 ` David Oberhollenzer
  2022-03-28  7:27 ` Richard Weinberger
  0 siblings, 2 replies; 7+ messages in thread
From: Rafał Miłecki @ 2022-03-25 12:00 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger; +Cc: linux-mtd, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

Such blocks may be incorrectly treated as empty (even though they may
have non-erase OOB). Warn about it so people may start suing
--skip-all-ffs .

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 nand-utils/nandwrite.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/nand-utils/nandwrite.c b/nand-utils/nandwrite.c
index e8a210c..cd53a17 100644
--- a/nand-utils/nandwrite.c
+++ b/nand-utils/nandwrite.c
@@ -280,6 +280,7 @@ int main(int argc, char * const argv[])
 	libmtd_t mtd_desc;
 	int ebsize_aligned;
 	uint8_t write_mode;
+	size_t all_ffs_cnt = 0;
 
 	process_options(argc, argv);
 
@@ -417,6 +418,8 @@ int main(int argc, char * const argv[])
 	 */
 	while ((imglen > 0 || writebuf < filebuf + filebuf_len)
 		&& mtdoffset < mtd.size) {
+		bool allffs;
+
 		/*
 		 * New eraseblock, check for bad block(s)
 		 * Stay in the loop to be sure that, if mtdoffset changes because
@@ -555,7 +558,8 @@ int main(int argc, char * const argv[])
 		}
 
 		ret = 0;
-		if (!skipallffs || !buffer_check_pattern(writebuf, mtd.min_io_size, 0xff)) {
+		allffs = buffer_check_pattern(writebuf, mtd.min_io_size, 0xff);
+		if (!allffs || !skipallffs) {
 			/* Write out data */
 			ret = mtd_write(mtd_desc, &mtd, fd, mtdoffset / mtd.eb_size,
 					mtdoffset % mtd.eb_size,
@@ -564,6 +568,8 @@ int main(int argc, char * const argv[])
 					writeoob ? oobbuf : NULL,
 					writeoob ? mtd.oob_size : 0,
 					write_mode);
+			if (!ret && allffs)
+				all_ffs_cnt++;
 		}
 
 		if (ret) {
@@ -615,6 +621,11 @@ closeall:
 		   || (writebuf < filebuf + filebuf_len))
 		sys_errmsg_die("Data was only partially written due to error");
 
+	if (all_ffs_cnt) {
+		fprintf(stderr, "Written %zu blocks containing only 0xff bytes\n", all_ffs_cnt);
+		fprintf(stderr, "Those block may be incorrectly treated as empty!\n");
+	}
+
 	/* Return happy */
 	return EXIT_SUCCESS;
 }
-- 
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2022-03-28  8:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-25 12:00 [PATCH mtd-utils] nandwrite: warn about writing 0xff blocks Rafał Miłecki
2022-03-28  6:51 ` David Oberhollenzer
2022-03-28  7:28   ` Richard Weinberger
2022-03-28  7:27 ` Richard Weinberger
2022-03-28  8:29   ` Rafał Miłecki
2022-03-28  8:45     ` Miquel Raynal
2022-03-28  8:51       ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox