mtd/util flash_otp_write.c,1.2,1.3

kyungmin.park at samsung.com kyungmin.park at samsung.com
Tue Feb 21 19:26:41 EST 2006


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

Modified Files:
	flash_otp_write.c 
Log Message:
[MTD] OneNAND: One-Time Programmable (OTP) support

One Block of the NAND Flash Array memory is reserved as
a One-Time Programmable Block memory area.
Also, 1st Block of NAND Flash Array can be used as OTP.

The OTP block can be read, programmed and locked using the same
operations as any other NAND Flash Array memory block.
OTP block cannot be erased.

OTP block is fully-guaranteed to be a valid block.


Index: flash_otp_write.c
===================================================================
RCS file: /home/cvs/mtd/util/flash_otp_write.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- flash_otp_write.c	7 Nov 2005 11:15:10 -0000	1.2
+++ flash_otp_write.c	22 Feb 2006 00:26:38 -0000	1.3
@@ -15,9 +15,10 @@
 
 int main(int argc,char *argv[])
 {
-	int fd, val, ret, size, wrote;
+	int fd, val, ret, size, wrote, len;
+	mtd_info_t mtdInfo;
 	off_t offset;
-	char *p, buf[256];
+	char *p, buf[2048];
 
 	if (argc != 4 || strcmp(argv[1], "-u")) {
 		fprintf(stderr, "Usage: %s -u <device> <offset>\n", argv[0]);
@@ -39,6 +40,11 @@
 		return errno;
 	}
 
+	if (ioctl(fd, MEMGETINFO, &mtdInfo)) {
+		perror("MEMGETINFO");
+		return errno;
+	}
+
 	offset = strtoul(argv[3], &p, 0);
 	if (argv[3][0] == 0 || *p != 0) {
 		fprintf(stderr, "%s: bad offset value\n", argv[0]);
@@ -52,14 +58,24 @@
 
 	printf("Writing OTP user data on %s at offset 0x%lx\n", argv[2], offset);
 
+	if (mtdInfo.type == MTD_NANDFLASH)
+		len = mtdInfo.oobblock;
+	else
+		len = 256;
+
 	wrote = 0;
-	while ((size = read(0, buf, sizeof(buf)))) {
+	while ((size = read(0, buf, len))) {
 		if (size < 0) {
 			perror("read()");
 			return errno;
 		}
 		p = buf;
 		while (size > 0) {
+			if (mtdInfo.type == MTD_NANDFLASH) {
+				/* Fill remain buffers with 0xff */
+				memset(buf + size, 0xff, mtdInfo.oobblock - size);
+				size = mtdInfo.oobblock;
+			}
 			ret = write(fd, p, size);
 			if (ret < 0) {
 				perror("write()");





More information about the linux-mtd-cvs mailing list