From cd494f74b780729817f7e3e3dd25138e3835eb54 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 6 Jun 2011 00:09:12 -0400 Subject: flash_{lock,unlock}: merge into one util Now that the utils have equivalent functionality, merge the two source code bases so they can't diverge in the future. Signed-off-by: Mike Frysinger Signed-off-by: Artem Bityutskiy --- flash_unlock.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'flash_unlock.c') diff --git a/flash_unlock.c b/flash_unlock.c index 690825d..759a5bc 100644 --- a/flash_unlock.c +++ b/flash_unlock.c @@ -1,11 +1,17 @@ /* - * FILE flash_unlock.c - * - * This utility unlock all sectors of flash device. + * flash_{lock,unlock} * + * utilities for locking/unlocking sectors of flash devices */ +#ifndef PROGRAM_NAME #define PROGRAM_NAME "flash_unlock" +#define FLASH_MSG "unlock" +#define FLASH_UNLOCK 1 +#else +#define FLASH_MSG "lock" +#define FLASH_UNLOCK 0 +#endif #include #include @@ -20,7 +26,7 @@ int main(int argc, char *argv[]) { - int fd; + int fd, request; struct mtd_info_user mtdInfo; struct erase_info_user mtdLockInfo; int count; @@ -69,12 +75,14 @@ int main(int argc, char *argv[]) mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize; } if (mtdLockInfo.start + mtdLockInfo.length > mtdInfo.size) { - fprintf(stderr, "unlock range is more than device supports\n"); + fprintf(stderr, "%s range is more than device supports\n", FLASH_MSG); exit(1); } - if (ioctl(fd, MEMUNLOCK, &mtdLockInfo)) { - fprintf(stderr, "Could not unlock MTD device: %s\n", argv[1]); + request = FLASH_UNLOCK ? MEMUNLOCK : MEMLOCK; + if (ioctl(fd, request, &mtdLockInfo)) { + fprintf(stderr, "Could not %s MTD device: %s\n", + FLASH_MSG, argv[1]); close(fd); exit(1); } -- cgit v1.2.3