#define CONFIG_MTD_NAND_LOGICAL_ADDRESS_ACCESS #include #include #include #include #include #include #include #include #include #include #include static int open_mtd(void) { int fd; mtd_info_t meminfo; /* Open the device */ if((fd = open("/dev/mtd1", O_RDWR)) == -1) { if((fd = open("/dev/mtd/1", O_RDWR)) == -1) { perror("open flash"); exit(1); } } /* Fill in MTD device capability structure */ if(ioctl(fd, MEMGETINFO, &meminfo) != 0) { perror("MEMGETINFO"); close(fd); exit(1); } /* Make sure device page sizes are valid */ if( !(meminfo.oobsize == 64 && meminfo.oobblock == 2048) && !(meminfo.oobsize == 16 && meminfo.oobblock == 512 ) && !(meminfo.oobsize == 8 && meminfo.oobblock == 256 ) ) { printf("Unknown flash (not normal NAND)\n"); close(fd); exit(1); } return fd; } static void read_mtd(int mfd, loff_t offset, size_t len, void *buf) { struct read_laddr_info_user rinfo; rinfo.from = offset; rinfo.len = len; rinfo.buf = (u_char *) buf; if (ioctl(mfd, MEMREADLADDR, &rinfo) != 0) { perror("ioctl(MEMREADLADDR)"); close(mfd); exit(1); } } int main(char *argv[]) { int mfd; unsigned int boot_partition; unsigned int fsro_partition; mfd = open_mtd(); read_mtd(mfd, 0x60004, 4, &boot_partition); read_mtd(mfd, 0x60014, 4, &fsro_partition); close(mfd); printf("ROOT end: %08x\n", boot_partition); printf("FSRO end: %08x\n", fsro_partition); } return 0; }