mtd/util nftl_format.c,1.18,1.19

David Woodhouse dwmw2 at infradead.org
Wed May 1 06:59:07 EDT 2002


Update of /home/cvs/mtd/util
In directory phoenix.infradead.org:/tmp/cvs-serv4632

Modified Files:
	nftl_format.c 
Log Message:
Take bad zones into account when calculating FormattedSize.


Index: nftl_format.c
===================================================================
RCS file: /home/cvs/mtd/util/nftl_format.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- nftl_format.c	26 Apr 2002 23:37:48 -0000	1.18
+++ nftl_format.c	1 May 2002 10:59:04 -0000	1.19
@@ -56,6 +56,8 @@
 #define cpu_to_le16(x) (x)
 #define cpu_to_le32(x) (x)
 #endif
+#define le32_to_cpu(x) cpu_to_le32(x)
+#define le16_to_cpu(x) cpu_to_le16(x)
 
 extern ssize_t pread(), pwrite();
 
@@ -185,7 +187,7 @@
 int main(int argc, char **argv)
 {
 	unsigned long startofs = 0, part_size = 0;
-	unsigned long ezones = 0, ezone = 0;
+	unsigned long ezones = 0, ezone = 0, bad_zones = 0;
 	unsigned char unit_factor = 0xFF;
 
 	long MediaUnit1 = -1, MediaUnit2 = -1;
@@ -272,18 +274,20 @@
 			} else if (MediaUnit2 == -1) {
 				MediaUnit2 = ezone;
 			}
+		} else {
+			bad_zones++;
 		}
 	}
 	printf("\n");
 
-	/* N.B. form dump of M-System original chips, NumEraseUnits counts the 2 Erase Unit used
+	/* N.B. from dump of M-System original chips, NumEraseUnits counts the 2 Erase Unit used
 	   by MediaHeader and the FirstPhysicalEUN starts from the MediaHeader */
 	NFTLhdr = (struct NFTLMediaHeader *) (writebuf[0]);
 	strcpy(NFTLhdr->DataOrgID, "ANAND");
 	NFTLhdr->NumEraseUnits = cpu_to_le16(part_size / meminfo.erasesize);
 	NFTLhdr->FirstPhysicalEUN = cpu_to_le16(MediaUnit1);
 	/* N.B. we reserve 2 more Erase Units for "folding" of Virtual Unit Chain */
-	NFTLhdr->FormattedSize = cpu_to_le32(part_size - (4 * meminfo.erasesize));
+	NFTLhdr->FormattedSize = cpu_to_le32(part_size - ( (5+bad_zones) * meminfo.erasesize));
 	NFTLhdr->UnitSizeFactor = unit_factor;
 
 	/* Phase 2. Writing NFTL Media Headers and Bad Unit Table */
@@ -293,7 +297,13 @@
 		pwrite(fd, BadUnitTable + ezone, 512,
 		       (MediaUnit1 * meminfo.erasesize) + 512 * (1 + ezone / 512));
 	}
-
+#if 0
+	printf("  MediaHeader contents:\n");
+	printf("    NumEraseUnits: %d\n", le16_to_cpu(NFTLhdr->NumEraseUnits));
+	printf("    FirstPhysicalEUN: %d\n", le16_to_cpu(NFTLhdr->FirstPhysicalEUN));
+	printf("    FormattedSize: %d (%d sectors)\n", le32_to_cpu(NFTLhdr->FormattedSize),
+	       le32_to_cpu(NFTLhdr->FormattedSize)/512);
+#endif
 	printf("Phase 2.b Writing Spare NFTL Media Header and Spare Bad Unit Table\n");
 	pwrite(fd, writebuf[0], 512, MediaUnit2 * meminfo.erasesize);
 	for (ezone = 0; ezone < (meminfo.size / meminfo.erasesize); ezone += 512) {





More information about the linux-mtd-cvs mailing list