diff options
author | David Woodhouse <dwmw2@shinybook.infradead.org> | 2006-04-11 19:09:16 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@shinybook.infradead.org> | 2006-04-11 19:09:16 -0400 |
commit | 72212c137c574b564723327af751c4054c7cfca6 (patch) | |
tree | 13be2da9d4be695002d6ea9c396660c986e5fa5c /flash_otp_lock.c |
Initial commit
Diffstat (limited to 'flash_otp_lock.c')
-rw-r--r-- | flash_otp_lock.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/flash_otp_lock.c b/flash_otp_lock.c new file mode 100644 index 0000000..bd56df3 --- /dev/null +++ b/flash_otp_lock.c @@ -0,0 +1,70 @@ +/* + * flash_otp_lock.c -- lock area of One-Time-Program data +*/ + +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <stdlib.h> +#include <errno.h> +#include <sys/ioctl.h> + +#include <mtd/mtd-user.h> + +int main(int argc,char *argv[]) +{ + int fd, val, ret, offset, size; + char *p, buf[8]; + + if (argc != 5 || strcmp(argv[1], "-u")) { + fprintf(stderr, "Usage: %s -u <device> <offset> <size>\n", argv[0]); + fprintf(stderr, "offset and size must match on OTP region boundaries\n"); + fprintf(stderr, "CAUTION! ONCE LOCKED, OTP REGIONS CAN'T BE UNLOCKED!\n"); + return EINVAL; + } + + fd = open(argv[2], O_WRONLY); + if (fd < 0) { + perror(argv[2]); + return errno; + } + + val = MTD_OTP_USER; + ret = ioctl(fd, OTPSELECT, &val); + if (ret < 0) { + perror("OTPSELECT"); + return errno; + } + + offset = strtoul(argv[3], &p, 0); + if (argv[3][0] == 0 || *p != 0) { + fprintf(stderr, "%s: bad offset value\n", argv[0]); + return ERANGE; + } + + size = strtoul(argv[4], &p, 0); + if (argv[4][0] == 0 || *p != 0) { + fprintf(stderr, "%s: bad size value\n", argv[0]); + return ERANGE; + } + + printf("About to lock OTP user data on %s from 0x%x to 0x%x\n", + argv[2], offset, offset + size); + printf("Are you sure (yes|no)? "); + if (fgets(buf, sizeof(buf), stdin) && strcmp(buf, "yes\n") == 0) { + struct otp_info info; + info.start = offset; + info.length = size; + ret = ioctl(fd, OTPLOCK, &info); + if (ret < 0) { + perror("OTPLOCK"); + return errno; + } + printf("Done.\n"); + } else { + printf("Aborted\n"); + } + + return 0; +} |