diff options
author | Mike Frysinger <vapier@gentoo.org> | 2011-06-06 00:09:12 -0400 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-06-06 15:32:43 +0300 |
commit | cd494f74b780729817f7e3e3dd25138e3835eb54 (patch) | |
tree | 0bd8d643a9e17ee237b4cc71dbccb891634a094a /flash_unlock.c | |
parent | 6534b670520f7709b2ba73a853a50372653c4726 (diff) |
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 <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'flash_unlock.c')
-rw-r--r-- | flash_unlock.c | 22 |
1 files changed, 15 insertions, 7 deletions
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 <unistd.h> #include <stdlib.h> @@ -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); } |