[RFC] [PATCH] [MTD-UTILS]: flash_unlock: enhancing for unlocking of specified number of blocks

Vimal Singh vimal.newwork at gmail.com
Wed Dec 2 09:30:14 EST 2009


This patch enhances the flash_unlock utility to be able to do
unlocking for specified blocks range.
This patch also fixes calculation of 'length' as in previous patch.

Say there are 240 blocks present in the device. Then:
offset starts from: 0x0
and full size of device: 0x1E00000

doing: 240 * 0x20000 gives -> 0x1E00000
But last block address should be 0x1DE0000 (which spans for 0x20000
bytes, adding up to size of 0x1E00000)

Signed-off-by: Vimal Singh <vimalsingh at ti.com>
---

--- a/flash_unlock.c	2009-11-24 19:33:18.000000000 +0530
+++ b/flash_unlock.c	2009-11-24 19:36:18.000000000 +0530
@@ -21,13 +21,14 @@ int main(int argc, char *argv[])
 	int fd;
 	struct mtd_info_user mtdInfo;
 	struct erase_info_user mtdLockInfo;
+	int count;

 	/*
 	 * Parse command line options
 	 */
-	if(argc != 2)
+	if(argc < 2)
 	{
-		fprintf(stderr, "USAGE: %s <mtd device>\n", argv[0]);
+		fprintf(stderr, "USAGE: %s <mtd device> <offset in hex> <block
count in decimal number>\n", argv[0]);
 		exit(1);
 	}
 	else if(strncmp(argv[1], "/dev/mtd", 8) != 0)
@@ -50,8 +51,18 @@ int main(int argc, char *argv[])
 		exit(1);
 	}

-	mtdLockInfo.start = 0;
-	mtdLockInfo.length = mtdInfo.size;
+	if (argc > 2)
+		mtdLockInfo.start = strtol(argv[2], NULL, 0);
+	else
+		mtdLockInfo.start = 0;
+
+	if (argc > 3) {
+		count = strtol(argv[3], NULL, 0);
+		mtdLockInfo.length = mtdInfo.erasesize * count;
+	} else {
+		mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
+	}
+
 	if(ioctl(fd, MEMUNLOCK, &mtdLockInfo))
 	{
 		fprintf(stderr, "Could not unlock MTD device: %s\n", argv[1]);
@@ -61,4 +72,3 @@ int main(int argc, char *argv[])

 	return 0;
 }
-



More information about the linux-mtd mailing list