Patchwork [2/4] flash_info: allow people to get info on multiple devices

login
register
mail settings
Submitter Mike Frysinger
Date June 6, 2011, 6:22 p.m.
Message ID <1307384537-9607-2-git-send-email-vapier@gentoo.org>
Download mbox | patch
Permalink /patch/98985/
State Accepted, archived
Commit 0c9b09bc1e1b0aad1877fd3fbb23421f9c229123
Headers show

Comments

Mike Frysinger - June 6, 2011, 6:22 p.m.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 flash_info.c |   36 +++++++++++++++++++++---------------
 1 files changed, 21 insertions(+), 15 deletions(-)

Patch

diff --git a/flash_info.c b/flash_info.c
index d4887da..6c518b2 100644
--- a/flash_info.c
+++ b/flash_info.c
@@ -18,39 +18,45 @@ 
 static void usage(int status)
 {
 	fprintf(status ? stderr : stdout,
-		"Usage: %s <device>\n",
+		"Usage: %s <device> [devices]\n",
 		PROGRAM_NAME);
 	exit(status);
 }
 
 int main(int argc, char *argv[])
 {
-	int regcount;
-	int fd;
+	int fd, i, regcount;
 
 	if (argc < 2)
 		usage(1);
 	if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
 		usage(0);
 
-	/* Open and size the device */
-	fd = open(argv[1], O_RDONLY);
-	if (fd < 0)
-		sys_errmsg_die("could not open: %s", argv[1]);
-
-	if (ioctl(fd, MEMGETREGIONCOUNT, &regcount) == 0) {
-		int i;
+	for (i = 1; i < argc; ++i) {
+		const char *dev = argv[i];
+		int r;
 		region_info_t reginfo;
-		printf("Device %s has %d erase regions\n", argv[1], regcount);
-		for (i = 0; i < regcount; i++) {
-			reginfo.regionindex = i;
+
+		/* Open and size the device */
+		fd = open(dev, O_RDONLY);
+		if (fd < 0) {
+			sys_errmsg("could not open: %s", dev);
+			continue;
+		}
+
+		if (ioctl(fd, MEMGETREGIONCOUNT, &regcount))
+			continue;
+
+		printf("%s: %d erase regions\n", dev, regcount);
+		for (r = 0; r < regcount; ++r) {
+			reginfo.regionindex = r;
 			if (ioctl(fd, MEMGETREGIONINFO, &reginfo) == 0) {
 				printf("Region %d is at 0x%x with size 0x%x and "
-						"has 0x%x blocks\n", i, reginfo.offset,
+						"has 0x%x blocks\n", r, reginfo.offset,
 						reginfo.erasesize, reginfo.numblocks);
 			} else {
 				warnmsg("can not read region %d from a %d region device",
-					i, regcount);
+					r, regcount);
 			}
 		}
 	}