summaryrefslogtreecommitdiff
path: root/flash_info.c
blob: f8b7efaba326a21f3b5d094351afab2949cd32d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * flash_info.c -- print info about a MTD device
 */

#define PROGRAM_NAME "flash_info"

#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: %s device\n", PROGRAM_NAME);
		return 16;
	}

	/* 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, &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;
}