From 7d81790ced345585b1e647ca9d0f6678e7062fa4 Mon Sep 17 00:00:00 2001 From: Dongsheng Yang Date: Sat, 31 Oct 2015 11:12:01 +0800 Subject: mtd-utils: Restructure the mtd-utils source. * There is no code modification in this commit, only moving * the files to proper place. The user tools looks a little messy as we place almost the all tools in the root directory of mtd-utils. To make it more clear, I propose to introduce the following structure for our source code. mtd-utils/ |-- lib |-- include |-- misc-utils |-- jffsX-utils |-- nand-utils |-- nor-utils |-- ubi-utils |-- ubifs-utils `-- tests Signed-off-by: Dongsheng Yang Signed-off-by: Brian Norris --- misc-utils/flash_otp_lock.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 misc-utils/flash_otp_lock.c (limited to 'misc-utils/flash_otp_lock.c') diff --git a/misc-utils/flash_otp_lock.c b/misc-utils/flash_otp_lock.c new file mode 100644 index 0000000..3c39a2d --- /dev/null +++ b/misc-utils/flash_otp_lock.c @@ -0,0 +1,72 @@ +/* + * flash_otp_lock.c -- lock area of One-Time-Program data + */ + +#define PROGRAM_NAME "flash_otp_lock" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include "common.h" + +int main(int argc,char *argv[]) +{ + int fd, val, ret, offset, size; + char *p; + + if (argc != 5 || strcmp(argv[1], "-u")) { + fprintf(stderr, "Usage: %s -u \n", PROGRAM_NAME); + 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", PROGRAM_NAME); + return ERANGE; + } + + size = strtoul(argv[4], &p, 0); + if (argv[4][0] == 0 || *p != 0) { + fprintf(stderr, "%s: bad size value\n", PROGRAM_NAME); + return ERANGE; + } + + printf("About to lock OTP user data on %s from 0x%x to 0x%x\n", + argv[2], offset, offset + size); + if (prompt("Are you sure?", false)) { + 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; +} -- cgit v1.2.3