4 * This utility unlock all sectors of flash device.
8 #define PROGRAM_NAME "flash_unlock"
15 #include <sys/ioctl.h>
16 #include <sys/mount.h>
19 #include <mtd/mtd-user.h>
21 int main(int argc, char *argv[])
24 struct mtd_info_user mtdInfo;
25 struct erase_info_user mtdLockInfo;
29 * Parse command line options
33 fprintf(stderr, "USAGE: %s <mtd device> <offset in hex> <block count in decimal number>\n", PROGRAM_NAME);
36 else if(strncmp(argv[1], "/dev/mtd", 8) != 0)
38 fprintf(stderr, "'%s' is not a MTD device. Must specify mtd device: /dev/mtd?\n", argv[1]);
42 fd = open(argv[1], O_RDWR);
45 fprintf(stderr, "Could not open mtd device: %s\n", argv[1]);
49 if(ioctl(fd, MEMGETINFO, &mtdInfo))
51 fprintf(stderr, "Could not get MTD device info from %s\n", argv[1]);
57 mtdLockInfo.start = strtol(argv[2], NULL, 0);
59 mtdLockInfo.start = 0;
62 count = strtol(argv[3], NULL, 0);
63 mtdLockInfo.length = mtdInfo.erasesize * count;
65 mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
68 if(ioctl(fd, MEMUNLOCK, &mtdLockInfo))
70 fprintf(stderr, "Could not unlock MTD device: %s\n", argv[1]);