From: Brian Norris <computersforpeace@gmail.com>
To: <linux-mtd@lists.infradead.org>
Cc: Brian Norris <computersforpeace@gmail.com>
Subject: [PATCH mtd-utils 08/11] flash_{un,}lock: add MEMISLOCKED support
Date: Mon, 31 Aug 2015 15:34:29 -0700 [thread overview]
Message-ID: <1441060472-82169-9-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1441060472-82169-1-git-send-email-computersforpeace@gmail.com>
With the -i / --islocked flags.
Sample output:
# flash_lock --islocked /dev/mtd0
Device: /dev/mtd0
Start: 0
Len: 0x400000
Lock status: unlocked
Return code: 0
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
flash_unlock.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/flash_unlock.c b/flash_unlock.c
index be09347faa92..644360548601 100644
--- a/flash_unlock.c
+++ b/flash_unlock.c
@@ -7,6 +7,7 @@
enum flash_lock_request {
REQUEST_LOCK,
REQUEST_UNLOCK,
+ REQUEST_ISLOCKED,
};
#ifndef PROGRAM_NAME
@@ -32,18 +33,21 @@ enum flash_lock_request {
static const char *flash_msg[] = {
[ REQUEST_LOCK ] = "lock",
[ REQUEST_UNLOCK ] = "unlock",
+ [ REQUEST_ISLOCKED ] = "check lock status",
};
static void usage(int status)
{
fprintf(status ? stderr : stdout,
- "Utility to lock or unlock the flash. Default action: %s\n"
+ "Utility to lock, unlock, or check the lock status of the flash.\n"
+ "Default action: %s\n"
"\n"
"Usage: %s [options] [--] <mtd device> [offset [block count]]\n"
"\n"
"Options:\n"
" -h --help Display this help and exit\n"
" --version Display version information and exit\n"
+ " -i --islocked Check if flash region is locked\n"
" -l --lock Lock a region of flash\n"
" -u --unlock Unlock a region of flash\n"
"\n"
@@ -54,9 +58,10 @@ static void usage(int status)
exit(status);
}
-static const char short_opts[] = "hlu";
+static const char short_opts[] = "hilu";
static const struct option long_opts[] = {
{ "help", no_argument, 0, 'h' },
+ { "islocked", no_argument, 0, 'i' },
{ "lock", no_argument, 0, 'l' },
{ "unlock", no_argument, 0, 'u' },
{ "version", no_argument, 0, 'v' },
@@ -83,6 +88,10 @@ static void process_args(int argc, char *argv[])
case 'h':
usage(0);
break;
+ case 'i':
+ req = REQUEST_ISLOCKED;
+ req_set++;
+ break;
case 'l':
req = REQUEST_LOCK;
req_set++;
@@ -101,7 +110,7 @@ static void process_args(int argc, char *argv[])
}
if (req_set > 1) {
- errmsg("cannot specify more than one lock/unlock option");
+ errmsg("cannot specify more than one lock/unlock/islocked option");
usage(1);
}
@@ -139,6 +148,7 @@ int main(int argc, char *argv[])
struct mtd_info_user mtdInfo;
struct erase_info_user mtdLockInfo;
int count;
+ int ret;
process_args(argc, argv);
@@ -179,13 +189,25 @@ int main(int argc, char *argv[])
case REQUEST_UNLOCK:
request = MEMUNLOCK;
break;
+ case REQUEST_ISLOCKED:
+ request = MEMISLOCKED;
+ break;
default:
errmsg_die("unknown request type: %d", req);
break;
}
- if (ioctl(fd, request, &mtdLockInfo))
+ ret = ioctl(fd, request, &mtdLockInfo);
+ if (ret < 0)
sys_errmsg_die("could not %s device: %s\n",
flash_msg[req], dev);
+ if (req == REQUEST_ISLOCKED) {
+ printf("Device: %s\n", dev);
+ printf("Start: %#0x\n", mtdLockInfo.start);
+ printf("Len: %#0x\n", mtdLockInfo.length);
+ printf("Lock status: %s\n", ret ? "locked" : "unlocked");
+ printf("Return code: %d\n", ret);
+ }
+
return 0;
}
--
2.5.0.457.gab17608
next prev parent reply other threads:[~2015-08-31 22:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-31 22:34 [PATCH mtd-utils 00/11] flash_{un,}lock upgrades Brian Norris
2015-08-31 22:34 ` [PATCH mtd-utils 01/11] flash_{un, }lock: nest optional parameters in help message Brian Norris
2015-08-31 22:34 ` [PATCH mtd-utils 02/11] flash_{un,}lock: switch to getopt library Brian Norris
2015-08-31 22:34 ` [PATCH mtd-utils 03/11] flash_{un,}lock: support --version flag Brian Norris
2015-08-31 22:34 ` [PATCH mtd-utils 04/11] flash_{un,}lock: document option flags Brian Norris
2015-08-31 22:34 ` [PATCH mtd-utils 05/11] flash_{un, }lock: abstract the argument positions Brian Norris
2015-08-31 22:34 ` [PATCH mtd-utils 06/11] flash_{un, }lock: move args processing to its own function Brian Norris
2015-08-31 22:34 ` [PATCH mtd-utils 07/11] flash_{un, }lock: support both lock/unlock in the same binary Brian Norris
2015-08-31 22:34 ` Brian Norris [this message]
2015-08-31 22:34 ` [PATCH mtd-utils 09/11] flash_{un, }lock: improve strtol() error handling Brian Norris
2015-08-31 22:34 ` [PATCH mtd-utils 10/11] flash_{un,}lock: don't allow "last byte + 1" Brian Norris
2015-08-31 22:34 ` [PATCH mtd-utils 11/11] flash_{un,}lock: document block count == -1 Brian Norris
2015-11-11 22:13 ` [PATCH mtd-utils 00/11] flash_{un,}lock upgrades Brian Norris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1441060472-82169-9-git-send-email-computersforpeace@gmail.com \
--to=computersforpeace@gmail.com \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).