* [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style
@ 2011-06-06 4:09 Mike Frysinger
2011-06-06 4:09 ` [PATCH 2/5] flash_{lock,unlock}: merge functionality Mike Frysinger
` (4 more replies)
0 siblings, 5 replies; 11+ messages in thread
From: Mike Frysinger @ 2011-06-06 4:09 UTC (permalink / raw)
To: linux-mtd
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
flash_info.c | 31 +++++++++++++------------------
flash_lock.c | 37 +++++++++++++++----------------------
flash_unlock.c | 16 +++++-----------
3 files changed, 33 insertions(+), 51 deletions(-)
diff --git a/flash_info.c b/flash_info.c
index ad7b30a..f8b7efa 100644
--- a/flash_info.c
+++ b/flash_info.c
@@ -14,44 +14,39 @@
#include <mtd/mtd-user.h>
-int main(int argc,char *argv[])
+int main(int argc, char *argv[])
{
int regcount;
- int Fd;
+ int fd;
- if (1 >= argc)
- {
- fprintf(stderr,"Usage: %s device\n", PROGRAM_NAME);
+ if (1 >= argc) {
+ fprintf(stderr, "Usage: %s device\n", PROGRAM_NAME);
return 16;
}
- // Open and size the device
- if ((Fd = open(argv[1],O_RDONLY)) < 0)
- {
- fprintf(stderr,"File open error\n");
+ /* Open and size the device */
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "File open error\n");
return 8;
}
- if (ioctl(Fd,MEMGETREGIONCOUNT,®count) == 0)
- {
+ if (ioctl(fd, MEMGETREGIONCOUNT, ®count) == 0) {
int i;
region_info_t reginfo;
printf("Device %s has %d erase regions\n", argv[1], regcount);
- for (i = 0; i < regcount; i++)
- {
+ for (i = 0; i < regcount; i++) {
reginfo.regionindex = i;
- if(ioctl(Fd, MEMGETREGIONINFO, ®info) == 0)
- {
+ if (ioctl(fd, MEMGETREGIONINFO, ®info) == 0) {
printf("Region %d is at 0x%x with size 0x%x and "
"has 0x%x blocks\n", i, reginfo.offset,
reginfo.erasesize, reginfo.numblocks);
- }
- else
- {
+ } else {
printf("Strange can not read region %d from a %d region device\n",
i, regcount);
}
}
}
+
return 0;
}
diff --git a/flash_lock.c b/flash_lock.c
index ef75234..8cd1b82 100644
--- a/flash_lock.c
+++ b/flash_lock.c
@@ -29,53 +29,46 @@ int main(int argc, char *argv[])
/*
* Parse command line options
*/
- if(argc != 4)
- {
+ if (argc != 4) {
fprintf(stderr, "USAGE: %s <mtd device> <ofs in hex> <num of sectors in decimal or -1 for all sectors>\n", PROGRAM_NAME);
exit(1);
- }
- else if(strncmp(argv[1], "/dev/mtd", 8) != 0)
- {
+ } else if (strncmp(argv[1], "/dev/mtd", 8) != 0) {
fprintf(stderr, "'%s' is not a MTD device. Must specify mtd device: /dev/mtd?\n", argv[1]);
exit(1);
}
fd = open(argv[1], O_RDWR);
- if(fd < 0)
- {
+ if (fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", argv[1]);
exit(1);
}
- if(ioctl(fd, MEMGETINFO, &mtdInfo))
- {
+ if (ioctl(fd, MEMGETINFO, &mtdInfo)) {
fprintf(stderr, "Could not get MTD device info from %s\n", argv[1]);
close(fd);
exit(1);
}
- sscanf(argv[2], "%x",&ofs);
- sscanf(argv[3], "%d",&num_sectors);
- if(ofs > mtdInfo.size - mtdInfo.erasesize)
- {
- fprintf(stderr, "%x is beyond device size %x\n",ofs,(unsigned int)(mtdInfo.size - mtdInfo.erasesize));
+ sscanf(argv[2], "%x", &ofs);
+ sscanf(argv[3], "%d", &num_sectors);
+ if (ofs > mtdInfo.size - mtdInfo.erasesize) {
+ fprintf(stderr, "%x is beyond device size %x\n", ofs,
+ (unsigned int)(mtdInfo.size - mtdInfo.erasesize));
exit(1);
}
if (num_sectors == -1) {
- num_sectors = mtdInfo.size/mtdInfo.erasesize;
- }
- else {
- if(num_sectors > mtdInfo.size/mtdInfo.erasesize)
- {
- fprintf(stderr, "%d are too many sectors, device only has %d\n",num_sectors,(int)(mtdInfo.size/mtdInfo.erasesize));
+ num_sectors = mtdInfo.size / mtdInfo.erasesize;
+ } else {
+ if (num_sectors > mtdInfo.size / mtdInfo.erasesize) {
+ fprintf(stderr, "%d are too many sectors, device only has %d\n",
+ num_sectors, (int)(mtdInfo.size / mtdInfo.erasesize));
exit(1);
}
}
mtdLockInfo.start = ofs;
mtdLockInfo.length = (num_sectors - 1) * mtdInfo.erasesize;
- if(ioctl(fd, MEMLOCK, &mtdLockInfo))
- {
+ if (ioctl(fd, MEMLOCK, &mtdLockInfo)) {
fprintf(stderr, "Could not lock MTD device: %s\n", argv[1]);
close(fd);
exit(1);
diff --git a/flash_unlock.c b/flash_unlock.c
index 3d29a92..26721a5 100644
--- a/flash_unlock.c
+++ b/flash_unlock.c
@@ -28,26 +28,21 @@ int main(int argc, char *argv[])
/*
* Parse command line options
*/
- if(argc < 2)
- {
+ if (argc < 2) {
fprintf(stderr, "USAGE: %s <mtd device> <offset in hex> <block count in decimal number>\n", PROGRAM_NAME);
exit(1);
- }
- else if(strncmp(argv[1], "/dev/mtd", 8) != 0)
- {
+ } else if (strncmp(argv[1], "/dev/mtd", 8) != 0) {
fprintf(stderr, "'%s' is not a MTD device. Must specify mtd device: /dev/mtd?\n", argv[1]);
exit(1);
}
fd = open(argv[1], O_RDWR);
- if(fd < 0)
- {
+ if (fd < 0) {
fprintf(stderr, "Could not open mtd device: %s\n", argv[1]);
exit(1);
}
- if(ioctl(fd, MEMGETINFO, &mtdInfo))
- {
+ if (ioctl(fd, MEMGETINFO, &mtdInfo)) {
fprintf(stderr, "Could not get MTD device info from %s\n", argv[1]);
close(fd);
exit(1);
@@ -65,8 +60,7 @@ int main(int argc, char *argv[])
mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
}
- if(ioctl(fd, MEMUNLOCK, &mtdLockInfo))
- {
+ if (ioctl(fd, MEMUNLOCK, &mtdLockInfo)) {
fprintf(stderr, "Could not unlock MTD device: %s\n", argv[1]);
close(fd);
exit(1);
--
1.7.5.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/5] flash_{lock,unlock}: merge functionality
2011-06-06 4:09 [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style Mike Frysinger
@ 2011-06-06 4:09 ` Mike Frysinger
2011-06-06 12:20 ` Artem Bityutskiy
2011-06-06 4:09 ` [PATCH 3/5] flash_{lock,unlock}: merge into one util Mike Frysinger
` (3 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Mike Frysinger @ 2011-06-06 4:09 UTC (permalink / raw)
To: linux-mtd
The flash_lock util has a bit of extra argument checking, and it supports
a magic value of "-1" to mean "all blocks".
The flash_unlock util supports automatic 2nd/3rd arguments to unlock the
whole flash. It also supports multiple bases (not just hex) for selecting
the range of the device to unlock.
So tweak both utilities so that they have equivalent functionality again
by adding the missing features to each.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
flash_lock.c | 41 +++++++++++++++++++++++------------------
flash_unlock.c | 17 +++++++++++++++--
2 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/flash_lock.c b/flash_lock.c
index 8cd1b82..164eaa4 100644
--- a/flash_lock.c
+++ b/flash_lock.c
@@ -23,14 +23,13 @@ int main(int argc, char *argv[])
int fd;
struct mtd_info_user mtdInfo;
struct erase_info_user mtdLockInfo;
- int num_sectors;
- int ofs;
+ int count;
/*
* Parse command line options
*/
- if (argc != 4) {
- fprintf(stderr, "USAGE: %s <mtd device> <ofs in hex> <num of sectors in decimal or -1 for all sectors>\n", PROGRAM_NAME);
+ if (argc < 2) {
+ fprintf(stderr, "USAGE: %s <mtd device> <offset> <block count>\n", PROGRAM_NAME);
exit(1);
} else if (strncmp(argv[1], "/dev/mtd", 8) != 0) {
fprintf(stderr, "'%s' is not a MTD device. Must specify mtd device: /dev/mtd?\n", argv[1]);
@@ -48,26 +47,32 @@ int main(int argc, char *argv[])
close(fd);
exit(1);
}
- sscanf(argv[2], "%x", &ofs);
- sscanf(argv[3], "%d", &num_sectors);
- if (ofs > mtdInfo.size - mtdInfo.erasesize) {
- fprintf(stderr, "%x is beyond device size %x\n", ofs,
- (unsigned int)(mtdInfo.size - mtdInfo.erasesize));
+
+ if (argc > 2)
+ mtdLockInfo.start = strtol(argv[2], NULL, 0);
+ else
+ mtdLockInfo.start = 0;
+ if (mtdLockInfo.start > mtdInfo.size) {
+ fprintf(stderr, "%#x is beyond device size %#x\n",
+ mtdLockInfo.start, mtdInfo.size);
+ close(fd);
exit(1);
}
- if (num_sectors == -1) {
- num_sectors = mtdInfo.size / mtdInfo.erasesize;
+ if (argc > 3) {
+ count = strtol(argv[3], NULL, 0);
+ if (count == -1)
+ mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
+ else
+ mtdLockInfo.length = mtdInfo.erasesize * count;
} else {
- if (num_sectors > mtdInfo.size / mtdInfo.erasesize) {
- fprintf(stderr, "%d are too many sectors, device only has %d\n",
- num_sectors, (int)(mtdInfo.size / mtdInfo.erasesize));
- exit(1);
- }
+ mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
+ }
+ if (mtdLockInfo.start + mtdLockInfo.length > mtdInfo.size) {
+ fprintf(stderr, "lock range is more than device supports\n");
+ exit(1);
}
- mtdLockInfo.start = ofs;
- mtdLockInfo.length = (num_sectors - 1) * mtdInfo.erasesize;
if (ioctl(fd, MEMLOCK, &mtdLockInfo)) {
fprintf(stderr, "Could not lock MTD device: %s\n", argv[1]);
close(fd);
diff --git a/flash_unlock.c b/flash_unlock.c
index 26721a5..690825d 100644
--- a/flash_unlock.c
+++ b/flash_unlock.c
@@ -29,7 +29,7 @@ int main(int argc, char *argv[])
* Parse command line options
*/
if (argc < 2) {
- fprintf(stderr, "USAGE: %s <mtd device> <offset in hex> <block count in decimal number>\n", PROGRAM_NAME);
+ fprintf(stderr, "USAGE: %s <mtd device> <offset> <block count>\n", PROGRAM_NAME);
exit(1);
} else if (strncmp(argv[1], "/dev/mtd", 8) != 0) {
fprintf(stderr, "'%s' is not a MTD device. Must specify mtd device: /dev/mtd?\n", argv[1]);
@@ -52,13 +52,26 @@ int main(int argc, char *argv[])
mtdLockInfo.start = strtol(argv[2], NULL, 0);
else
mtdLockInfo.start = 0;
+ if (mtdLockInfo.start > mtdInfo.size) {
+ fprintf(stderr, "%#x is beyond device size %#x\n",
+ mtdLockInfo.start, mtdInfo.size);
+ close(fd);
+ exit(1);
+ }
if (argc > 3) {
count = strtol(argv[3], NULL, 0);
- mtdLockInfo.length = mtdInfo.erasesize * count;
+ if (count == -1)
+ mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
+ else
+ mtdLockInfo.length = mtdInfo.erasesize * count;
} else {
mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
}
+ if (mtdLockInfo.start + mtdLockInfo.length > mtdInfo.size) {
+ fprintf(stderr, "unlock range is more than device supports\n");
+ exit(1);
+ }
if (ioctl(fd, MEMUNLOCK, &mtdLockInfo)) {
fprintf(stderr, "Could not unlock MTD device: %s\n", argv[1]);
--
1.7.5.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/5] flash_{lock,unlock}: merge into one util
2011-06-06 4:09 [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style Mike Frysinger
2011-06-06 4:09 ` [PATCH 2/5] flash_{lock,unlock}: merge functionality Mike Frysinger
@ 2011-06-06 4:09 ` Mike Frysinger
2011-06-06 12:24 ` Artem Bityutskiy
2011-06-06 4:09 ` [PATCH 4/5] flash_{lock,unlock}: convert to common code Mike Frysinger
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Mike Frysinger @ 2011-06-06 4:09 UTC (permalink / raw)
To: linux-mtd
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>
---
flash_lock.c | 81 ++-----------------------------------------------------
flash_unlock.c | 22 ++++++++++-----
2 files changed, 18 insertions(+), 85 deletions(-)
diff --git a/flash_lock.c b/flash_lock.c
index 164eaa4..33f76c7 100644
--- a/flash_lock.c
+++ b/flash_lock.c
@@ -1,83 +1,8 @@
/*
- * FILE flash_lock.c
- *
- * This utility locks one or more sectors of flash device.
+ * flash_{lock,unlock}
*
+ * utilities for locking/unlocking sectors of flash devices
*/
#define PROGRAM_NAME "flash_lock"
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <time.h>
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-#include <string.h>
-
-#include <mtd/mtd-user.h>
-
-int main(int argc, char *argv[])
-{
- int fd;
- struct mtd_info_user mtdInfo;
- struct erase_info_user mtdLockInfo;
- int count;
-
- /*
- * Parse command line options
- */
- if (argc < 2) {
- fprintf(stderr, "USAGE: %s <mtd device> <offset> <block count>\n", PROGRAM_NAME);
- exit(1);
- } else if (strncmp(argv[1], "/dev/mtd", 8) != 0) {
- fprintf(stderr, "'%s' is not a MTD device. Must specify mtd device: /dev/mtd?\n", argv[1]);
- exit(1);
- }
-
- fd = open(argv[1], O_RDWR);
- if (fd < 0) {
- fprintf(stderr, "Could not open mtd device: %s\n", argv[1]);
- exit(1);
- }
-
- if (ioctl(fd, MEMGETINFO, &mtdInfo)) {
- fprintf(stderr, "Could not get MTD device info from %s\n", argv[1]);
- close(fd);
- exit(1);
- }
-
- if (argc > 2)
- mtdLockInfo.start = strtol(argv[2], NULL, 0);
- else
- mtdLockInfo.start = 0;
- if (mtdLockInfo.start > mtdInfo.size) {
- fprintf(stderr, "%#x is beyond device size %#x\n",
- mtdLockInfo.start, mtdInfo.size);
- close(fd);
- exit(1);
- }
-
- if (argc > 3) {
- count = strtol(argv[3], NULL, 0);
- if (count == -1)
- mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
- else
- mtdLockInfo.length = mtdInfo.erasesize * count;
- } else {
- mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
- }
- if (mtdLockInfo.start + mtdLockInfo.length > mtdInfo.size) {
- fprintf(stderr, "lock range is more than device supports\n");
- exit(1);
- }
-
- if (ioctl(fd, MEMLOCK, &mtdLockInfo)) {
- fprintf(stderr, "Could not lock MTD device: %s\n", argv[1]);
- close(fd);
- exit(1);
- }
-
- return 0;
-}
+#include "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 <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);
}
--
1.7.5.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/5] flash_{lock,unlock}: convert to common code
2011-06-06 4:09 [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style Mike Frysinger
2011-06-06 4:09 ` [PATCH 2/5] flash_{lock,unlock}: merge functionality Mike Frysinger
2011-06-06 4:09 ` [PATCH 3/5] flash_{lock,unlock}: merge into one util Mike Frysinger
@ 2011-06-06 4:09 ` Mike Frysinger
2011-06-06 12:26 ` Artem Bityutskiy
2011-06-06 4:09 ` [PATCH 5/5] flash_{lock, unlock}: fix off-by-one error for "entire device" length Mike Frysinger
2011-06-06 12:19 ` [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style Artem Bityutskiy
4 siblings, 1 reply; 11+ messages in thread
From: Mike Frysinger @ 2011-06-06 4:09 UTC (permalink / raw)
To: linux-mtd
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
flash_unlock.c | 75 ++++++++++++++++++++++++++++++-------------------------
1 files changed, 41 insertions(+), 34 deletions(-)
diff --git a/flash_unlock.c b/flash_unlock.c
index 759a5bc..3d7dd53 100644
--- a/flash_unlock.c
+++ b/flash_unlock.c
@@ -22,48 +22,57 @@
#include <sys/mount.h>
#include <string.h>
+#include "common.h"
#include <mtd/mtd-user.h>
+static void usage(int status)
+{
+ fprintf(status ? stderr : stdout,
+ "Usage: %s <mtd device> [offset] [block count]\n\n"
+ "If offset is not specified, it defaults to 0.\n"
+ "If block count is not specified, it defaults to all blocks.\n",
+ PROGRAM_NAME);
+ exit(status);
+}
+
int main(int argc, char *argv[])
{
int fd, request;
struct mtd_info_user mtdInfo;
struct erase_info_user mtdLockInfo;
int count;
+ const char *dev;
/*
* Parse command line options
*/
- if (argc < 2) {
- fprintf(stderr, "USAGE: %s <mtd device> <offset> <block count>\n", PROGRAM_NAME);
- exit(1);
- } else if (strncmp(argv[1], "/dev/mtd", 8) != 0) {
- fprintf(stderr, "'%s' is not a MTD device. Must specify mtd device: /dev/mtd?\n", argv[1]);
- exit(1);
- }
+ if (argc < 2 || argc > 4)
+ usage(1);
+ if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
+ usage(0);
- fd = open(argv[1], O_RDWR);
- if (fd < 0) {
- fprintf(stderr, "Could not open mtd device: %s\n", argv[1]);
- exit(1);
- }
+ dev = argv[1];
+
+ /*
+ * Get the device info to compare to command line sizes
+ */
+ fd = open(dev, O_RDWR);
+ if (fd < 0)
+ sys_errmsg_die("could not open: %s", dev);
- if (ioctl(fd, MEMGETINFO, &mtdInfo)) {
- fprintf(stderr, "Could not get MTD device info from %s\n", argv[1]);
- close(fd);
- exit(1);
- }
+ if (ioctl(fd, MEMGETINFO, &mtdInfo))
+ sys_errmsg_die("could not get mtd info: %s", dev);
+ /*
+ * Make sure user options are valid
+ */
if (argc > 2)
mtdLockInfo.start = strtol(argv[2], NULL, 0);
else
mtdLockInfo.start = 0;
- if (mtdLockInfo.start > mtdInfo.size) {
- fprintf(stderr, "%#x is beyond device size %#x\n",
+ if (mtdLockInfo.start > mtdInfo.size)
+ errmsg_die("%#x is beyond device size %#x",
mtdLockInfo.start, mtdInfo.size);
- close(fd);
- exit(1);
- }
if (argc > 3) {
count = strtol(argv[3], NULL, 0);
@@ -71,21 +80,19 @@ int main(int argc, char *argv[])
mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
else
mtdLockInfo.length = mtdInfo.erasesize * count;
- } else {
+ } else
mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
- }
- if (mtdLockInfo.start + mtdLockInfo.length > mtdInfo.size) {
- fprintf(stderr, "%s range is more than device supports\n", FLASH_MSG);
- exit(1);
- }
+ if (mtdLockInfo.start + mtdLockInfo.length > mtdInfo.size)
+ errmsg_die("range is more than device supports: %#x + %#x > %#x",
+ mtdLockInfo.start, mtdLockInfo.length, mtdInfo.size);
+ /*
+ * Finally do the operation
+ */
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);
- }
+ if (ioctl(fd, request, &mtdLockInfo))
+ sys_errmsg_die("could not %s device: %s\n",
+ FLASH_MSG, dev);
return 0;
}
--
1.7.5.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/5] flash_{lock, unlock}: fix off-by-one error for "entire device" length
2011-06-06 4:09 [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style Mike Frysinger
` (2 preceding siblings ...)
2011-06-06 4:09 ` [PATCH 4/5] flash_{lock,unlock}: convert to common code Mike Frysinger
@ 2011-06-06 4:09 ` Mike Frysinger
2011-06-06 12:28 ` Artem Bityutskiy
2011-06-06 12:19 ` [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style Artem Bityutskiy
4 siblings, 1 reply; 11+ messages in thread
From: Mike Frysinger @ 2011-06-06 4:09 UTC (permalink / raw)
To: linux-mtd; +Cc: Vimal Singh, Vimal Singh, Steven Miao
From: Steven Miao <realmz6@gmail.com>
This basically reverts commit 43feb39f35a9ee0ed3 which changed the full
length calculation to be one less than one sector. I don't understand
the logic in the commit message where it states that the length should
be one sector smaller as this results in misbehavior at runtime.
For example, with a mtd device with total size 0x400000 and erase block
size of 0x20000 (which gives us a total of 32 sectors), this new logic
results in:
mtdLockInfo.start = 0;
mtdLockInfo.length = 0x3e0000; /* (32 - 1) * 0x20000 */
Calling MEMLOCK/MEMUNLOCK on the device with this range leaves the last
sector unchanged which is certainly not what we want. So drop this -1
part of the calculation.
To look at it another way, if we only attempt to lock one sector, this
calculation would end up with the .length set to 0. Calling MEMLOCK
with a length of 0 does not lock the sector as this simple code shows:
int main(int argc, char *argv[]) {
erase_info_t e0 = { 0, 0 }, e1 = { 0, 0x20000 };
int fd = open(argv[1], O_RDONLY);
ioctl(fd, MEMUNLOCK, &e1);
printf("%i\n", ioctl(fd, MEMISLOCKED, &e1));
ioctl(fd, MEMLOCK, &e0);
printf("%i\n", ioctl(fd, MEMISLOCKED, &e1));
}
MEMISLOCKED returns 0 both times. If we change the argument to MEMLOCK
to e1, then MEMISLOCKED returns 1.
CC: Vimal Singh <vimal.newwork@gmail.com>
CC: Vimal Singh <vimalsingh@ti.com>
Signed-off-by: Steven Miao <realmz6@gmail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
flash_unlock.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/flash_unlock.c b/flash_unlock.c
index 3d7dd53..9fb089a 100644
--- a/flash_unlock.c
+++ b/flash_unlock.c
@@ -77,11 +77,11 @@ int main(int argc, char *argv[])
if (argc > 3) {
count = strtol(argv[3], NULL, 0);
if (count == -1)
- mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
+ mtdLockInfo.length = mtdInfo.size;
else
mtdLockInfo.length = mtdInfo.erasesize * count;
} else
- mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize;
+ mtdLockInfo.length = mtdInfo.size;
if (mtdLockInfo.start + mtdLockInfo.length > mtdInfo.size)
errmsg_die("range is more than device supports: %#x + %#x > %#x",
mtdLockInfo.start, mtdLockInfo.length, mtdInfo.size);
--
1.7.5.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style
2011-06-06 4:09 [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style Mike Frysinger
` (3 preceding siblings ...)
2011-06-06 4:09 ` [PATCH 5/5] flash_{lock, unlock}: fix off-by-one error for "entire device" length Mike Frysinger
@ 2011-06-06 12:19 ` Artem Bityutskiy
2011-06-06 12:19 ` Artem Bityutskiy
4 siblings, 1 reply; 11+ messages in thread
From: Artem Bityutskiy @ 2011-06-06 12:19 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Mon, 2011-06-06 at 00:09 -0400, Mike Frysinger wrote:
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> flash_info.c | 31 +++++++++++++------------------
> flash_lock.c | 37 +++++++++++++++----------------------
> flash_unlock.c | 16 +++++-----------
> 3 files changed, 33 insertions(+), 51 deletions(-)
Pushed to l2-mtd-2.6.git, thanks.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style
2011-06-06 12:19 ` [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style Artem Bityutskiy
@ 2011-06-06 12:19 ` Artem Bityutskiy
0 siblings, 0 replies; 11+ messages in thread
From: Artem Bityutskiy @ 2011-06-06 12:19 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Mon, 2011-06-06 at 15:19 +0300, Artem Bityutskiy wrote:
> On Mon, 2011-06-06 at 00:09 -0400, Mike Frysinger wrote:
> > Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> > ---
> > flash_info.c | 31 +++++++++++++------------------
> > flash_lock.c | 37 +++++++++++++++----------------------
> > flash_unlock.c | 16 +++++-----------
> > 3 files changed, 33 insertions(+), 51 deletions(-)
>
> Pushed to l2-mtd-2.6.git, thanks.
Err, sorry, to mtd-utils of course.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/5] flash_{lock,unlock}: merge functionality
2011-06-06 4:09 ` [PATCH 2/5] flash_{lock,unlock}: merge functionality Mike Frysinger
@ 2011-06-06 12:20 ` Artem Bityutskiy
0 siblings, 0 replies; 11+ messages in thread
From: Artem Bityutskiy @ 2011-06-06 12:20 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Mon, 2011-06-06 at 00:09 -0400, Mike Frysinger wrote:
> The flash_lock util has a bit of extra argument checking, and it supports
> a magic value of "-1" to mean "all blocks".
>
> The flash_unlock util supports automatic 2nd/3rd arguments to unlock the
> whole flash. It also supports multiple bases (not just hex) for selecting
> the range of the device to unlock.
>
> So tweak both utilities so that they have equivalent functionality again
> by adding the missing features to each.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Pushed to mtd-utils.git, thanks!
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/5] flash_{lock,unlock}: merge into one util
2011-06-06 4:09 ` [PATCH 3/5] flash_{lock,unlock}: merge into one util Mike Frysinger
@ 2011-06-06 12:24 ` Artem Bityutskiy
0 siblings, 0 replies; 11+ messages in thread
From: Artem Bityutskiy @ 2011-06-06 12:24 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Mon, 2011-06-06 at 00:09 -0400, Mike Frysinger wrote:
> 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>
Pushed, thanks.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/5] flash_{lock,unlock}: convert to common code
2011-06-06 4:09 ` [PATCH 4/5] flash_{lock,unlock}: convert to common code Mike Frysinger
@ 2011-06-06 12:26 ` Artem Bityutskiy
0 siblings, 0 replies; 11+ messages in thread
From: Artem Bityutskiy @ 2011-06-06 12:26 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Mon, 2011-06-06 at 00:09 -0400, Mike Frysinger wrote:
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> flash_unlock.c | 75 ++++++++++++++++++++++++++++++-------------------------
> 1 files changed, 41 insertions(+), 34 deletions(-)
Pushed, but tweaked a bit ...
> + /*
> + * Get the device info to compare to command line sizes
> + */
Made the comment style to be the same as we use in the kernel - one line
for short comments. Changed the existing comment as well. It could be a
separate patch, but let's use a simplified way in this case :-)
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 5/5] flash_{lock, unlock}: fix off-by-one error for "entire device" length
2011-06-06 4:09 ` [PATCH 5/5] flash_{lock, unlock}: fix off-by-one error for "entire device" length Mike Frysinger
@ 2011-06-06 12:28 ` Artem Bityutskiy
0 siblings, 0 replies; 11+ messages in thread
From: Artem Bityutskiy @ 2011-06-06 12:28 UTC (permalink / raw)
To: Mike Frysinger; +Cc: Vimal Singh, Vimal Singh, linux-mtd, Steven Miao
On Mon, 2011-06-06 at 00:09 -0400, Mike Frysinger wrote:
> From: Steven Miao <realmz6@gmail.com>
>
> This basically reverts commit 43feb39f35a9ee0ed3 which changed the full
> length calculation to be one less than one sector. I don't understand
> the logic in the commit message where it states that the length should
> be one sector smaller as this results in misbehavior at runtime.
Pushed as well, thanks!
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-06-06 12:32 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-06 4:09 [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style Mike Frysinger
2011-06-06 4:09 ` [PATCH 2/5] flash_{lock,unlock}: merge functionality Mike Frysinger
2011-06-06 12:20 ` Artem Bityutskiy
2011-06-06 4:09 ` [PATCH 3/5] flash_{lock,unlock}: merge into one util Mike Frysinger
2011-06-06 12:24 ` Artem Bityutskiy
2011-06-06 4:09 ` [PATCH 4/5] flash_{lock,unlock}: convert to common code Mike Frysinger
2011-06-06 12:26 ` Artem Bityutskiy
2011-06-06 4:09 ` [PATCH 5/5] flash_{lock, unlock}: fix off-by-one error for "entire device" length Mike Frysinger
2011-06-06 12:28 ` Artem Bityutskiy
2011-06-06 12:19 ` [PATCH 1/5] flash_lock/flash_unlock/flash_info: clean up style Artem Bityutskiy
2011-06-06 12:19 ` Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox