/* * flash_info.c -- print info about a MTD device */ #define PROGRAM_NAME "flash_info" #include #include #include #include #include #include #include #include "common.h" #include static void usage(int status) { fprintf(status ? stderr : stdout, "Usage: %s \n", PROGRAM_NAME); exit(status); } int main(int argc, char *argv[]) { int regcount; int fd; 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, ®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++) { reginfo.regionindex = i; 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 { warnmsg("can not read region %d from a %d region device", i, regcount); } } } return 0; }