/* NAND flash resize utility for Sharp Zaurus SL-C7x0/860 and SL-5600 version 1.0 Copyright 2004 Alexander Chukov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ #define CONFIG_MTD_NAND_LOGICAL_ADDRESS_ACCESS #include #include #include #include #include #include #include #include #include #include /* #include */ /* was for 2.4 kernels */ #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.writesize == 2048) && !(meminfo.oobsize == 16 && meminfo.writesize == 512 ) && !(meminfo.oobsize == 8 && meminfo.writesize == 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 mtd_oob_buf rinfo; rinfo.start = offset; rinfo.length = len; rinfo.ptr = (u_char *) buf; if (ioctl(mfd, MEMREADOOB, &rinfo) != 0) { perror("ioctl(MEMREADOOB)"); close(mfd); exit(1); } } int main(int argc, char *argv[]) { int mfd; unsigned int boot_partition; unsigned int fsro_partition; unsigned int fsrw_partition; mfd = open_mtd(); read_mtd(mfd, 0x60004, 4, &boot_partition); read_mtd(mfd, 0x60014, 4, &fsro_partition); read_mtd(mfd, 0x60024, 4, &fsrw_partition); close(mfd); if (argc > 1) { } else { /* printf("ROOT end: %08x\n", boot_partition); printf("FSRO end: %08x\n", fsro_partition); printf("FSRW end: %08x (for SL-C700/750 and SL-5600 only)\n", fsrw_partition); */ printf("FSRO size: %d MB\n", (fsro_partition - boot_partition)/(1024*1024)); } return 0; }