summaryrefslogtreecommitdiff
path: root/flash_info.c
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@shinybook.infradead.org>2006-04-11 19:09:16 -0400
committerDavid Woodhouse <dwmw2@shinybook.infradead.org>2006-04-11 19:09:16 -0400
commit72212c137c574b564723327af751c4054c7cfca6 (patch)
tree13be2da9d4be695002d6ea9c396660c986e5fa5c /flash_info.c
Initial commit
Diffstat (limited to 'flash_info.c')
-rw-r--r--flash_info.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/flash_info.c b/flash_info.c
new file mode 100644
index 0000000..7157b9e
--- /dev/null
+++ b/flash_info.c
@@ -0,0 +1,55 @@
+/*
+ * flash_info.c -- print info about a MTD device
+*/
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+
+#include <mtd/mtd-user.h>
+
+int main(int argc,char *argv[])
+{
+ int regcount;
+ int Fd;
+
+ if (1 >= argc)
+ {
+ fprintf(stderr,"Usage: flash_info device\n");
+ return 16;
+ }
+
+ // Open and size the device
+ if ((Fd = open(argv[1],O_RDONLY)) < 0)
+ {
+ fprintf(stderr,"File open error\n");
+ return 8;
+ }
+
+ if (ioctl(Fd,MEMGETREGIONCOUNT,&regcount) == 0)
+ {
+ int i;
+ region_info_t reginfo;
+ printf("Device %s has %d erase regions\n", argv[1], regcount);
+ for (i = 0; i < regcount; i++)
+ {
+ reginfo.regionindex = i;
+ 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,
+ reginfo.erasesize, reginfo.numblocks);
+ }
+ else
+ {
+ printf("Strange can not read region %d from a %d region device\n",
+ i, regcount);
+ }
+ }
+ }
+ return 0;
+}